五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > JQuery控制radio選中不選中和獲取radio選中值方法總結

JQuery控制radio選中不選中和獲取radio選中值方法總結

文章來源:365jz.com     點擊數(shù):612    更新時間:2017-08-08 15:02   參與評論

一、設置選中方法


$("input[name='名字']").get(0).checked=true; 

$("input[name='名字']").attr('checked','true');

$("input[name='名字']:eq(0)").attr("checked",'checked'); 

$("input[name='radio_name'][checked]").val();  //獲取被選中Radio的Value值

 

二、設置選中和不選中示例


<input type="radio" value="0" name="jizai" id="0"/>否

<input type="radio" value="1" name="jizai"  id="1"/>是

#jquery中,radio的選中與否是這么設置的。

$("#rdo1").attr("checked","checked");

$("#rdo1").removeAttr("checked");

 

通過name


$("input:radio[name="analyfsftype"]").eq(0).attr("checked",'checked');

$("input:radio[name="analyshowtype"]").attr("checked",false);



通過id


$("#tradeType0").attr("checked","checked");

$("#tradeType1").attr("checked",false);

 

三、另一種設置選中方法

 


<script type="text/javascript">  

$(document).ready(function(){  

        $("input[@type=radio][name=sex][@value=1]").attr("checked",true);  

});  

</script>  



您的性別:  


<input type="radio" name="sex" value="1" <s:if test="user.sex==1">checked</s:if>/>男  

<input type="radio" name="sex" value="0" <s:if test="user.sex==0">checked</s:if>/>女

 

四、根據(jù)值設置radio選中

 


$("input[name='radio_name'][value='要選中Radio的Value值']").attr("checked",true);  //根據(jù)Value值設置Radio為選中狀態(tài)

 

五、使用prop方法操作示例

 


$('input').removeAttr('checked'); 

$($('#'+id+'input').eq(0)).prop('checked',false);

$($('#'+id+' input').eq(0)).prop('checked',true);

 

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.根據(jù)索引值設置任意一個radio為選中值:

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

或者

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

5.根據(jù)Value值設置Radio為選中值

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

或者

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

6.刪除Value值為rd2的Radio

$("input:radio[value=http://www.2cto.com/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){

     //寫入代碼

});

如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答??! 點擊進入論壇

發(fā)表評論 (612人查看,0條評論)
請自覺遵守互聯(lián)網(wǎng)相關的政策法規(guī),嚴禁發(fā)布色情、暴力、反動的言論。
昵稱:
最新評論
2017年08月08日 15:06游客

正是我需要的,學習了

------分隔線----------------------------

其它欄目

· 建站教程
· 365學習

業(yè)務咨詢

· 技術支持
· 服務時間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權所有 鄂ICP備17013400號