selectAll—part II

来源:互联网 发布:在淘宝买甩棍违法吗 编辑:程序博客网 时间:2024/06/07 00:37

之前写过一个全选的,以下是从
http://blog.csdn.net/fcc0429/article/details/74931807
摘抄的布局;

<div id="formdiv">    <input type="checkbox" name="checkoption">篮球<p>    <input type="checkbox" name="checkoption">足球    <p>        <input type="checkbox" name="checkoption">网球    <p>        <input type="checkbox" name="checkoption">台球    <p>        <input type="checkbox" id="selectAll">        <label for="selectAll">全选</label></div>

这次使用jquery来写

$(        $inputItem = $("input[name='checkoption']"),        $selectAll = $("#selectAll"),        $selectAll.click(function () {            $inputItem.each(function () {                $(this).prop("checked", $selectAll.prop("checked"))            })        }),        $("#formdiv").delegate($inputItem, "click", function () {            $inputItem.each(function () {        $inputChecked=$("input[name='checkoption']:checked").length;                if($inputChecked===$inputItem.length){                    $selectAll.prop("checked", true)                }                else {                    $selectAll.prop("checked", false)                }            })        })    )

这里用input.cheked.length用的很好;
就是在想,以上代码是否有什么性能上的问题?

原创粉丝点击