开发者

Create master checkbox outside {foreach} tag

开发者 https://www.devze.com 2023-01-05 02:33 出处:网络
I have dynamic page under {foreach} tag something like this. <div id=\"c1\"> {foreach} <input type=\"checkbox\" name=\"checkbox\" id=\"{$num}\" checked/>

I have dynamic page under {foreach} tag something like this.

<div id="c1">
{foreach}
<input type="checkbox" name="checkbox" id="{$num}" checked/>
{/foreach}
</div>

which in return prints something like this.

<div id="c1">
<input type="checkbox" name="checkbox1" id="1" checked/>
<input type="checkbox" name="checkbox2" id="2" checked/>
<input type="checkbox" name="checkbox3" id="3" 开发者_StackOverflow社区checked/>
</div>

What I want is to hide <div id="c1"> & show only one checkbox outside <div id="c1">

controlling all checkboxes which are inside <div id="c1">

How can I achieve this ?

Thanks.

  • Mandar


You mean something like this?

Try it out: http://jsfiddle.net/3Hjam/ (click the checkbox in the right panel)

HTML

<div id="c1">
    <input type="checkbox" name="checkbox1" id="1" checked />
    <input type="checkbox" name="checkbox2" id="2" checked />
    <input type="checkbox" name="checkbox3" id="3" checked />
</div>
<input type="checkbox" name="master" id="master" checked />

jQuery

$('#c1').hide();

$('#master').change(function() {
        // Click the children of c1 when the master is clicked
    $('#c1').children().click();

        // Display the current values in an alert
    var result = $('#c1').children().map(function() {
        return $(this).attr('checked');
    }).get().join(',');

    alert(result);
});
0

精彩评论

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