开发者

Changing CheckBox states in facebox using jQuery / AJAX

开发者 https://www.devze.com 2023-03-21 19:46 出处:网络
I am using jQuery AJAX to dynamically lo开发者_开发百科ad web user control\'s HTML via web service into one of my <div> element.

I am using jQuery AJAX to dynamically lo开发者_开发百科ad web user control's HTML via web service into one of my <div> element.

This works absolutely fine, without any problem.

The problem arises when I use facebox plugin to show that div as a popup. I have Select All / None checkboxes in this div which should select all checkboxes or deselect all of them.

When I click the links select all / none and try to select all checkboxes through jQuery, nothing happens and nothing reflects on my checkboxes until I close my popup and reopen it.

As soon as I reopen my popup iIcan see that all checkboxes are checked.

What might be the problem?


Without an example of your code, it's a little difficult to really understand what you want, but I'll make a guess. Here's one way to make a "select all" checkbox:

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");
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消