selectAll—part II

xiaoxiao2021-02-28  99

之前写过一个全选的,以下是从 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用的很好; 就是在想,以上代码是否有什么性能上的问题?

转载请注明原文地址: https://www.6miu.com/read-59849.html

最新回复(0)