zoukankan      html  css  js  c++  java
  • jQuery设置全选和全反选

    
    

    HTML 代码:

    <input type="checkbox" id="allChecked" onclick="setAllChecked(this.checked)" />
    <input type="checkbox" name="hobby" onclick="setCheckedAll()" value="1" />

    JavaScript 脚本:

    /**
     * 设置“全选”或“全反选”
     */
    var setAllChecked = function(isAllChecked){
    	if(isAllChecked) {
    		$('input[name=hobby]').prop("checked", true);
    	} else {
    		$('input[name=hobby]').prop("checked", false);
    	}
    }
    
    
    
    
    /**
     * 设置“选全”或“反选全”
     */
    var setCheckedAll = function(){
    	var hobbyCount = $('input[name=hobby]').length;
    	var checkedCount = $('input[name=hobby]:checked').length;
    	
    	if(hobbyCount === checkedCount) {
    		$('#allChecked').prop("checked", true);
    	} else {
    		$('#allChecked').prop("checked", false);
    	}
    }
    

      

      

     

  • 相关阅读:
    练习5.6.3节
    size_t
    练习3.43
    use include to read a file
    ACM数学(转)
    POJ 2039 To and Fro
    poj 1716 差分约束
    poj 3159 差分约束
    hdu 4571 floyd+动态规划
    poj 1364 差分约束
  • 原文地址:https://www.cnblogs.com/hapday/p/6561969.html
Copyright © 2011-2022 走看看