通过本文主要向大家介绍了DropdownList,RadioButtonList,CheckboxList等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
一: DropDownList
-------------------------------------------------------------------------------------------
在使用 JQuery 进行遍历操作时,
$("input").each(function(i) {
......
}
当操作对象的类型为 dropdownlist时:(备注:在firefox下DropDownList的类型为"select-one")
获得所选中的值: $(this).val(); (如果不是遍历操作时,$(this) 就替换成 $('#控件的Id') )
获取选中的文本: $(this).find("option:selected").text(); 或者 $("#控件的name option:selected").text();
获取选中的索引: $(this).get(0).selectedIndex;
二:RadioButtonList
-------------------------------------------------------------------------------------------
如果页面只有一个RadioButtonList时,可以直接用 $("input[type='radio']:checked").val() 来获得 所选中的值
如果页面有2个或多个RadioButtonList时:
第一步: 取到RadioButtonList控件的Id,设置 var objId=控件Id;
第二步:取到控件的Name, 设置 var radioName = $("input[id^='" + objId + "']").eq(0).attr('name');
第三步:取值
获得所选中的值: $("input[name='" + radioName + "']:checked").val());
获得所选中的文本: $("input[name='" + radioName + "']:checked+label").text());
三:CheckBoxList
-------------------------------------------------------------------------------------------
判断是否有选中的一个方法,objId为 CheckBoxList的 Id
目前暂时无法用js直接获得服务器控件CheckBoxList的value值,只能通过一些小技巧来实现,例如添加额外的属性
代码中 selectedText 是获得 所选中的文本值,selectedValue 是获得 所选中的值
-------------------------------------------------------------------------------------------
在使用 JQuery 进行遍历操作时,
$("input").each(function(i) {
......
}
当操作对象的类型为 dropdownlist时:(备注:在firefox下DropDownList的类型为"select-one")
获得所选中的值: $(this).val(); (如果不是遍历操作时,$(this) 就替换成 $('#控件的Id') )
获取选中的文本: $(this).find("option:selected").text(); 或者 $("#控件的name option:selected").text();
获取选中的索引: $(this).get(0).selectedIndex;
二:RadioButtonList
-------------------------------------------------------------------------------------------
如果页面只有一个RadioButtonList时,可以直接用 $("input[type='radio']:checked").val() 来获得 所选中的值
如果页面有2个或多个RadioButtonList时:
第一步: 取到RadioButtonList控件的Id,设置 var objId=控件Id;
第二步:取到控件的Name, 设置 var radioName = $("input[id^='" + objId + "']").eq(0).attr('name');
第三步:取值
获得所选中的值: $("input[name='" + radioName + "']:checked").val());
获得所选中的文本: $("input[name='" + radioName + "']:checked+label").text());
三:CheckBoxList
-------------------------------------------------------------------------------------------
判断是否有选中的一个方法,objId为 CheckBoxList的 Id
目前暂时无法用js直接获得服务器控件CheckBoxList的value值,只能通过一些小技巧来实现,例如添加额外的属性
代码中 selectedText 是获得 所选中的文本值,selectedValue 是获得 所选中的值
您可能想查找下面的文章:
- DropDownList实现可输入可选择(两种版本可选)
- JQuery组件基于Bootstrap的DropDownList(完整版)
- Jquery操作下拉框(DropDownList)实现取值赋值
- GridView中获取被点击行中的DropDownList和TextBox中的值
- Jquery加载时从后台读取数据绑定到dropdownList实例
- ASP.NET jQuery 实例18 通过使用jQuery validation插件校验DropDownList
- ASP.NET jQuery 实例8 (动态添加内容到DropDownList)
- ASP.NET jQuery 实例7 通过jQuery来获取DropDownList的Text/Value属性值
- Jquery中的CheckBox、RadioButton、DropDownList的取值赋值实现代码
- JQuery中对服务器控件 DropdownList, RadioButtonList, CheckboxList的操作总结