Jquery获取radio选中值实例总结
Radio
1.获取选中值,三种方法都可以
$('input:radio:checked').val(); $("input[type='radio']:checked").val(); $("input[name='rd']:checked").val();
2.设置第一个Radio为选中值
$('input:radio:first').attr('checked', 'checked'); 或者 $('input:radio:first').attr('checked', 'true');
注attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3.设置一个Radio为选中值
$('input:radio:last').attr('checked', 'checked'); 或者 $('input:radio:last').attr('checked', 'true');
4.根据索引值设置任意一个radio为选中值
$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2.... 或者 $('input:radio').slice(1,2).attr('checked', 'true');
5.根据Value值设置Radio为选中值
$("input:radio[value=//.jb51./kf/201110/'rd2']").attr('checked','true'); 或者 $("input[value=//.jb51./kf/201110/'rd2']").attr('checked','true');
6.删除Value值为rd2的Radio
$("input:radio[value=//.jb51./kf/201110/'rd2']").remove();
7.删除第几个Radio
$("input:radio").eq(索引值).remove();索引值=0,1,2.... 如删除第3个Radio:$("input:radio").eq(2).remove();
8.遍历Radio
$('input:radio').each(function(index,domEle){ //写入代码 });
DropDownList
1. 获取选中项
获取选中项的Value值
$('select#sel option:selected').val();
或者
$('select#sel').find('option:selected').val();
获取选中项的Text值
$('select#seloption:selected').text();
或者
$('select#sel').find('option:selected').text();
2. 获取当前选中项的索引值
$('select#sel').get(0).selectedIndex;
3. 获取当前option的最大索引值
$('select#sel option:last').attr("index")
4. 获取DropdownList的长度
$('select#sel')[0].options.length;
或者
$('select#sel').get(0).options.length;
5. 设置第一个option为选中值
$('select#sel option:first').attr('selected','true')
或者
$('select#sel')[0].selectedIndex = 0;
6. 设置一个option为选中值
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南