Jquery checkbox 全选和取消全选 ( 同一页面支持多个)

发布时间:2018-04-25作者:laosun阅读(1533)

    1524645997760023885.png


    实现方式:

    <th><label><input type="checkbox" name="all" child="index_" class="ace"><span class="lbl"></span></label></th>
    <th><label><input type="checkbox" name="all" child="index2_" class="ace"><span class="lbl"></span></label></th>
    以下是循环出来的多列数据:
    <td><label><input type="checkbox" name="id" id="index_" class="ace"><span class="lbl"></span></label></td>
    <td><label><input type="checkbox" name="id" id="index2_" class="ace"><span class="lbl"></span></label></td>
    <script type="text/javascript">
    	$(document).ready(function(e) {
    		$("input[name=all]").click(function() {
    			var idName = $(this).attr("child");
    			if ($(this).is(':checked')) {
    				$("input[id=" + idName + "]").prop("checked", true);
    			} else {
    				$("input[id=" + idName + "]").prop("checked", false);
    			}
    		});
    	});
    	//jquery 获取选中的值
    	function batchSpiderTo(id) {
    		$("input:checkbox[id=" + id + "]:checked").each(function() {
    			alert($(this).attr("attr"));
    		});
    	}
    </script>


0 +1

版权声明

 jquery  前端  源码  javascript

 请文明留言

0 条评论