2011-07-20 59 views
0

我正在使用jQuery AJAX通過web服務將web用戶控件的HTML動態加載到我的<div>元素之一中。
這工作絕對好,沒有任何問題。使用jQuery/AJAX更改facebox中的CheckBox狀態

當我使用facebox插件將div顯示爲彈出窗口時,問題就出現了。我在此div中選擇全部/無複選框,應該選中所有複選框或取消選擇全部複選框。
當我點擊鏈接選擇所有/沒有並嘗試通過jQuery來選擇所有的複選框,沒有任何反應,沒有什麼對我的複選框反映,直到我閉上彈出,然後重新打開。
只要我重新打開我的彈出窗口,iIcan就會看到所有複選框都被選中。
可能是什麼問題?

+0

很難說沒有看到代碼,但我的猜測是,你需要使用.live()方法在facebox div中的複選框上,因爲facebox在頁面加載完成後呈現。 – charliegriefer

回答

0

沒有你的代碼的例子,有點難以真正理解你想要的,但我會猜測。這裏是做一個「全選」複選框的一種方法:

HTML:

<input type="checkbox" class="select-all" name="select-all" id="select-all" value="select all" /> 
<label for="select-all">Select All</label> 
<input type="checkbox" class="checkbox" name="checkbox1" id="checkbox1" value="1"/> 
<input type="checkbox" class="checkbox" name="checkbox2" id="checkbox2" value="2"/> 
<input type="checkbox" class="checkbox" name="checkbox3" id="checkbox3" value="3"/> 
<input type="checkbox" class="checkbox" name="checkbox4" id="checkbox4" value="4"/> 
<input type="checkbox" class="checkbox" name="checkbox5" id="checkbox5" value="5"/> 

的jQuery:

$("#select-all").click(function(){ 
    if ($(this).attr("checked") == "checked") { 
     $(".checkbox").attr("checked", "checked"); 
    } else { 
     $(".checkbox").removeAttr("checked"); 
    } 
});