<div id="test">
    <table>
      <tr><td><input type="checkbox" id="id1" value="item1"/></td></tr>
    </table>
    <div>
       <table><tr><td><input type="checkbox" id="id2"  value="item2"/></td></tr></table>
       <table><tr><td><input type="checkbox" id="id3" value="item3"/></td></tr></table>
       <div><table><tr><td><input id="id4" type="checkbox" value="item4"/></td></tr></table>
            <div><table><tr><td><input id="id5" type="checkbox" value="item5"/></td></tr></table></div>
       </div>
    </div>
    </div>
需求是:当我点击id="id1"的checkbox时,id2、id3、id4、id5的checkbox都要选中,当点击id3时,id4,id5被选中,当然啦,点击id4时,id5也要被选中。由于用户可用积分也只有十来分,所以给分就少点。请见凉。jQueryCheckBox

解决方案 »

  1.   

    onclik事件、注意的你的结账率
      

  2.   


    $(document).ready(function () {
                $("#test :checkbox").click(function () {
                    $(this).parents('table').nextAll().each(function () {
                        $(this).find(':checkbox').each(function () {
                            if ($(this).attr('checked') == undefined) {
                                $(this).attr('checked', 'checked');
                            } else {
                                $(this).attr('checked', false);
                            }
                        });
                    });
                });
            });
      

  3.   


    $(function(){
    $("input").click(function(event){
    if($("#"+event.target.id).is(":checked")){
    for (var i=$('input').index($('#'+event.target.id)), l=$('input').length; i<=l;i++){
    $("input").eq(i).attr("checked","checked");
    }
    } else {
    for (var i=$('input').index($('#'+event.target.id)), l=$('input').length; i<=l;i++){
    $("input").eq(i).removeAttr("checked");
    }
    }
    });
    })只实现了一次 求大神解释
      

  4.   

    可以在你的id1 id3 id4 里写单击事件,然后在这里面把你想要的功能实现就可以,这样最直接,也最容易理解.