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

jquery 操作 Radio大全

WBOY
Release: 2016-06-01 09:54:51
Original
1110 people have browsed it

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

代码如下:

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


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

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

 

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

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

 

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

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

 

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

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

 

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>
Copy after login


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

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

 

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

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

 

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

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

 

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

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

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

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template