欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery控制radio選中和不選中方法總結(jié)

 更新時間:2015年04月15日 12:00:36   投稿:junjie  
這篇文章主要介紹了JQuery控制radio選中和不選中方法總結(jié),本文起講解了設(shè)置選中方法、設(shè)置選中和不選中示例、另一種設(shè)置選中方法、根據(jù)值設(shè)置radio選中、使用prop方法操作示例等內(nèi)容,需要的朋友可以參考下

一、設(shè)置選中方法

復(fù)制代碼 代碼如下:

$("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值

二、設(shè)置選中和不選中示例

復(fù)制代碼 代碼如下:

<input type="radio" value="0" name="jizai" id="0"/>否
<input type="radio" value="1" name="jizai"  id="1"/>是
#jquery中,radio的選中與否是這么設(shè)置的。
$("#rdo1").attr("checked","checked");
$("#rdo1").removeAttr("checked");

通過name

復(fù)制代碼 代碼如下:

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

通過id
復(fù)制代碼 代碼如下:

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

三、另一種設(shè)置選中方法

復(fù)制代碼 代碼如下:

<script type="text/javascript"> 
$(document).ready(function(){ 
        $("input[@type=radio][name=sex][@value=1]").attr("checked",true); 
}); 
</script> 

您的性別: 
復(fù)制代碼 代碼如下:

<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ù)值設(shè)置radio選中

復(fù)制代碼 代碼如下:

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

五、使用prop方法操作示例

復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評論