您的位置:首页 > Web前端 > JQuery

jquery-radio

2016-04-21 15:25 543 查看
1.获取选中值,三种方法都可以:

$('input:radio:checked').val();

$("input[type='radio']:checked").val();

$("input[name='rd']:checked").val();

2.设置第一个Radio为选中值:

   $('input:radio:first').prop('checked', 'checked');

或者

$('input:radio:first').prop('checked', 'true');

注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)

3.设置最后一个Radio为选中值:

$('input:radio:last').prop('checked', 'checked');

或者

$('input:radio:last').prop('checked', 'true');

4.根据索引值设置任意一个radio为选中值:

$('input:radio').eq(索引值).prop('checked', 'true');索引值=0,1,2....

或者

$('input:radio').slice(1,2).prop'checked', 'true');

5.根据Value值设置Radio为选中值

$("input:radio[value=http://www.2cto.com/kf/201110/'rd2']").prop('checked','true');

或者

$("input[value=http://www.2cto.com/kf/201110/'rd2']").prop('checked','true');

6. 取消radio 

$("#tradeType1").prop("checked",false);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: