zoukankan      html  css  js  c++  java
  • JS 获取radiobuttonlist checkboxlist的值

    js 取得CheckBoxList的选中项的值,遍历RadioButtonList
     

    获取CheckBoxList的值

    var CheckBoxList=document.all.CheckBoxList1;
    var objCheckBox,CheckValue="";
    for(i=0;i<CheckBoxList.rows.length;i++)  
    {  
         objCheckBox   =    document.getElementById("CheckBoxList1_"   +    i);
          if(objCheckBox.checked == true)
        {
                 CheckValue += CheckBoxList.rows[i].cells[0].childNodes(1).innerText + ",";  
           }
    }
    if(CheckValue!="")
        alert(CheckValue)

    遍历RadioButtonList

    var ItemCount = document.all.RadioButtonList1.length;
           for (i = 0; i < ItemCount; i++)
           {
            if (g("RadioButtonList_" + i))
             alert(document.getElementById("RadioButtonList_" + i).value);
           }

    JQuery 获取checkboxlist 值

    (document).ready(function() {
        $("#btnShow").click(function() {
            var valuelist = ""; //保存checkbox选中值
            //遍历name以listTest开头的checkbox
            $("input[name^='listTest']").each(function() {
                if (this.checked) {
                    //$(this):当前checkbox对象;
                    //$(this).parent("span"):checkbox父级span对象
                    valuelist += $(this).parent("span").attr("alt") + ",";
                }
            });
            if (valuelist.length > 0) {
                //得到选中的checkbox值序列,结果为400,398
                valuelist = valuelist.substring(0, valuelist.length - 1);
            }
        });

    JQuery 获取radiobuttonlist 的值
    var SelectVal = $("input[name='ctl00$ContentPlaceHolder1$rbl_typeid']:checked").val();   



    });

  • 相关阅读:
    生产力-能力-生产工具
    window.location.Reload()和window.location.href 区别
    getAttribute() 与 attr() 的区别
    清空标签间的内容(innerHTML)和 value
    使用 data-* 属性来嵌入自定义数据:
    JS-jquery 获取当前点击的对象
    Redis深度历险——核心原理与应用实践
    PhpStorm 配置 Xdebug调试工具
    phpCOW机制详解
    rel=nofollow 是什么意思
  • 原文地址:https://www.cnblogs.com/xffy1028/p/2344338.html
Copyright © 2011-2022 走看看