Home >Web Front-end >JS Tutorial >jquery 操作 Radio大全

jquery 操作 Radio大全

WBOY
WBOYOriginal
2016-06-01 09:54:511125browse

1、改变radio的选择,触发一些效果

代码如下:

<code class="language-javascript">$("input:radio[name='dialCheckResult']").change(function (){ //拨通
alert(“123”);
});</code>


2、让页面中所有的radio可用

<code class="language-javascript">$("input:radio").attr("disabled",false);</code>

 

3、让页面中所有的radio不可用

<code class="language-javascript">$("input:radio").attr("disabled","disabled");</code>

 

4、让某个radio置于选中状态

<code class="language-javascript">$("input:radio[name='dialCheckResult']").eq(0).attr("checked",true);</code>

 

5、让页面中“未选中”状态的radio不可用

<code class="language-javascript">$("input:radio:not([checked])").attr("disabled","disabled");</code>

 

6、遍历选中状态的radio,除了某一个radio之外,其他的“选中”状态的radio设定是“未选中”状态

代码如下:

<code class="language-javascript">$('input:radio:checked').each(function(i,val){
if(val.name != "dialCheckResult" ){
$("input:radio[name='"+val.name+"']:checked").attr('checked',false);
}
});</code>


7、让所有“未选中”状态的radio不可用

<code class="language-javascript">$("input:radio:not([checked])").attr("disabled","disabled");</code>

 

8、获得某个选中的特定NAME的radio的值

<code class="language-javascript">var dialCheckResult=$("input:radio[name='dialCheckResult']:checked").val() ;</code>

 

9、让所有“选中”状态的radio置于“未选中”状态

<code class="language-javascript">$('input:radio:checked').attr('checked',false);</code>

 

10、让页面中的radio都置于“选中”状态或“未选中”状态

<code class="language-javascript">$("input:radio").attr("checked",true);

$("input:radio").attr("checked",false);</code>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn