click事件

来源:互联网 发布:知页简历 编辑:程序博客网 时间:2024/05/17 21:06

click事件

一、dom添加onclick

<section>    <ul>        <li onclick="getSelect(this)">            <div>                <input type="checkbox" value="" id="checkboxInput_1" name="" />            </div>        </li>    </ul></section>
//点击li选中checkboxfunction getSelect(obj) {    $(obj).find("input:checkbox").each(function(i) {        if($(this).attr("checked") == "checked") {            $(this).removeAttr("checked");        } else {            $(this).attr("checked", "checked");        }    });    return false;}

二、

<section>    <ul>        <li>            <div>                <input type="checkbox" value="" id="checkboxInput_1" name="" />            </div>        </li>    </ul></section>
// 点击li选中checkbox$("ul").on("click", "li", function() {    $(this).find("input:checkbox").each(function(i) {        if($(this).attr("checked") == "checked") {            $(this).removeAttr("checked");        } else {            $(this).attr("checked", "checked");        }    });    return false;});

三、

<section>    <ul>        <li id="li_click">            <div>                <input type="checkbox" value="" id="checkboxInput_1" name="" />            </div>        </li>    </ul></section>
$("#li_click").click(function() {    $(this).find("input:checkbox").each(function(i) {        if($(this).attr("checked") == "checked") {            $(this).removeAttr("checked");        } else {            $(this).attr("checked", "checked");        }    });    return false;});
0 0