2010-05-07 33 views
1

我有一個iFrame像這樣:如何在點擊按鈕時將iFrame中選中的複選框的值序列化爲隱藏表單域?

<iframe width="100%" frameborder="0" height="470" allowtransparency="true" name="productframe" id="productframe" style="border-bottom:1px solid #eee"></iframe> 

iframe的包含從SQL Server數據庫得出的幾個訂單項,我可以檢查任何我想與執行任務的複選框的 - 在這種情況下將其刪除。我在父文檔中有一個按鈕,其中顯示「刪除選定」,我希望能夠單擊此按鈕並使用子iframe中選定複選框的值填充父頁中的隱藏字段。

我的複選框看起來像這樣:

<input id="Checkbox1" type="checkbox" value="47" title="Select this row" name="selectItem"/> 

我的jQuery的實例,我父頁面上,所以我可以使用jQuery選擇的,我只是不知道,以做到這一點所需的語法。

在此先感謝任何能夠幫助我的人。

回答

1

如果這些複選框不是一種形式,像

var ifr = $('iframe').contents(), 
var chb = ifr.find('input:checkbox'); 

if(chb.length){ 
    ifr.find('body').append($('<form/>', { 
     id: 'tempform', 
     css: {display:none;} 
    })); 
    ifr.find('input:checkbox').each(function(){ 
     ifr.find('#tempform').append($(this).clone()); 
    } 

    var serializedString = ifr.find('#tempform').serialize();  
    // do something with the serializedString 
    ifr.find('#tempform').remove(); 
} 

,你可以把serializedString成隱藏字段。嗯可能是矯枉過正,但我​​是在心情:p 這一切都沒有經過測試。

+0

這讓我進一步到了我想去的地方,所以謝謝。我用的你的建議一下調版本:) \t功能getChecked( \t { \t VAR IFR = $( '#productframe')的內容(); \t // var chb = ifr.find('input:checkbox'); \t var serializedString = ifr.find('#catform')。serialize(); \t \t document.form1.selecteditems.value = serializedString; \t document.form1.action ='DataSphere-Delete.asp'; \t document.form1.submit() \t} – 2010-05-07 14:50:16

相關問題