zoukankan      html  css  js  c++  java
  • jquery之prop与attr区别。

    一切看下面代码示例
    <!DOCTYPE html> <html> <head> <title>全选和反选</title> <script type="text/javascript" src="./jquery-1.11.2.min.js"></script> </head> <body> <input type="checkbox" name="chkFirst"><br/> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec"> <input type="checkbox" name="chkSec" > </body> <script type="text/javascript"> var chkFirst = $('input[name="chkFirst"]'); var chkSec = $('input[name="chkSec"]'); chkFirst.click(function(){ // 这里的prop代替attr是因为prop可循环执行,而attr只能执行一次 // is函数判断对象属性,反坏true和false chkSec.prop("checked", $(this).is(":checked")); }); var len = chkSec.length; chkSec.click(function(){ // 在这里也不能用attr chkFirst.prop("checked", $('input[name="chkSec"]:checked').length == len?true:false); }); </script> </html>
  • 相关阅读:
    DLX
    逆康托展开
    康托展开
    light oj 1427(ac自动机)
    hdu 2586 (lca-RMQ)
    约瑟夫问题
    C-运算符
    C-数据
    shell-流程控制
    python编程规范-最佳实践
  • 原文地址:https://www.cnblogs.com/qqblog/p/6659308.html
Copyright © 2011-2022 走看看