zoukankan      html  css  js  c++  java
  • jQuerycheckbox全选/取消全选

    用JavaScript使页面上的一组checkbox全选/取消全选,逻辑很简单,实现代码也没有太难的语法。但使用jQuery实现则更简单,代码也很简洁,精辟!

    jQuery版本:1.3.2

    Code

    jQuery.attr  获取/设置对象的属性值,如:

    $("input[name='chk_list']").attr("checked");     //读取所有name为'chk_list'对象的状态(是否选中)

    $("input[name='chk_list']").attr("checked",true);      //设置所有name为'chk_list'对象的checked为true

    再如:

    $("#img_1").attr("src","test.jpg");    //设置ID为img_1的<img>src的值为'test.jpg'
    $("#img_1").attr("src");     //读取ID为img_1的<img>src值

     下面的代码是获取上面实例中选中的checkbox的value值:

    Code

     哪位高手能把上面遍历的过程用$.each()写出来,不胜感激。

    在此谢谢rainnoless的帮助,下面是用$.each()遍历的代码:

    <script type="text/javascript">
        
    var arrChk=$("input[name='chk_list']:checked");
        $(arrChk).each(
    function(){
           window.alert(
    this.value);                        
        }
    ); 
    });
    </script>
  • 相关阅读:
    一个开源库:720全景显示
    如何查看mac系统是32位还是64位的操作系统
    iOS ASIHTTPRequest 使用指南
    iOS block里的self
    苹果公司给出的检测 advertisingIdentifier 的方法
    App Store idfa被拒检查办法
    iOS苹果开发者客服电话地址
    iOS项目的目录结构和开发流程(Cocoa China)
    CFBundleVersion与CFBundleShortVersionString
    In App Purchase Statuses
  • 原文地址:https://www.cnblogs.com/bynet/p/1602491.html
Copyright © 2011-2022 走看看