ASP.NET服务器端控件RadioButtonList,DropDownList,Che(2)


//默认选中第二项
var rbts = document.getElementsByName("RadioButtonList1");
            for (var i = 0; i < rbts.length; i++) {
                if (rbts[i].value == "1")
                    rbts[i].checked = "true";
            }

2、DropDownList

1)取值

复制代码 代码如下:


 $("#DropDownList1").change(function () {
//弹出选中项的Val值
                alert($("#DropDownList1").val());
//弹出选中项的text值
                alert($("#DropDownList1 option:selected").text());
            });

2)赋值

复制代码 代码如下:


//默认选中第二项
var ddls = $("#DropDownList1 option");
                        for (var i = 0; i < ddl.length; i++) {
                            if (ddl[i].value == "1") {
                                ddl[i].selected = "true";
                            }
                        }

3、CheckBoxList

1)取值 

复制代码 代码如下:


$("#CheckBoxList1 > input").click(function () {
               var arrval = [];
                var val = "";
              $("#CheckBoxList1 :checkbox:checked").each(function () {
             //将选中项的值放进数组arrval
                    arrval.push($(this).val())
                })
            //将数组中的val值以‘,'进行连接
                val = arrval.join(',');
              //弹出所有选择的项以,连接
                                alert(val);
                var arrtext = [];
                var text = "";
                $("#CheckBoxList1 :checkbox:checked").each(function () {
              //将选中项的text值放进arrtext数组中
                    arrtext.push($(this).next().html());
              //将数组中的数据用,进行连接
                    text = arrtext.join(",");
                })
             //弹出选中项的Text值
               alert(text);
                });

2)赋值

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjggyp.html