<input type="radio">如下:
<input type="radio" name="city" value="BeiJing">北京 <input type="radio" name="city" value="TianJin">天津 <input type="radio" name="city" value="NanJing">南京 <input type="radio" name="city" value="YangZhou">扬州 <input type="radio" name="city" value="SuZhou">苏州
1、获取选中的radio的值:
$("input[name='city']:checked").val();
使用元素选择器,再使用属性过滤器name='city',最后使用:checked选取被选中的元素。
2、给指定值的radio设置选中状态
$("input[name='city'][value='YangZhou']").attr("checked",true);
给name="city"而且value="YangZhou"的radio设置选中状态。
3、取消name="city"的radio的选中状态
$('input[name="city"]:checked').attr("checked",false);
4、获取name="city"的radio的个数:
$("input[name='city']").length;
5、获取name="city"而且索引是偶数的radio:
$("input[name='city']:even");
索引是从0开始的。
6、获取name="city"而且索引是奇数的radio:
$("input[name='city']:odd");
索引是从0开始的。
7、迭代radio:
$("input[name='city']").each(function(i,obj){ //i,迭代的下标,从0开始 //obj,当前的对象(HTMLInputElement),可以使用obj.value格式获取属性值 //$(this);当前jQuery对象,可以使用$(this).val()获取属性值 });
迭代name="city"的radio。
8、禁用radio:
$("input[name='city']").attr("disabled",true);
禁用name="city"的radio。
9、启用radio:
$("input[name='city']").attr("disabled",false);
启用name="city"的radio。
相关推荐
jQuery操作input type=radio的实现代码,需要的朋友可以参考下
input type="radio" name="loaders" value="circular-loading" checked="checked"/> <span>circular</span> </label> <label> <input type="radio" name="loaders" value="circle-loading"/> <span>...
<input type="radio" name="a"/>1<input type="radio" name="a"/>2<br/> <input type="reset" /><br/> <input type="submit" value="提交"/><br/> <input type="text" /><br/> <select><option>Option</option>...
jquery取radio单选按钮的值$(“input[name=’items’]:checked”).val();jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值 var item = $(...
<label><input type="radio" name="sex" value="男" checked="checked" />男</label> <label><input type="radio" name="sex" value="女" />女</label> </div> </td> </tr> <tr> <td class=...
创建一个 <input> 元素必须同时设定 type 属性。因为微软规定 <input> 元素的 type 只能写一次。 jQuery 代码: // 在 IE 中无效: $("<input>").attr("type", "checkbox"); // 在 IE 中有效: $("<input type='...
<i class='input_style radio_bg'><input type="radio" name="hot" value="1"></i> a1 </lable> <lable> <i class='input_style radio_bg'><input type="radio" name="hot" value="2"></i> ...
<input name="radio" type="radio" class="mui-radio">Item 5 </li> <li class="mui-table-view-cell mui-radio mui-left"> <input name="radio" type="radio">Item 6 </...
<input type="radio" name="rdo" class="rdolist" checked="checked" /> <label class="rdobox"> <span class="check-image"></span> <span class="radiobox-content">男</span> </label> <!--多选--> <input ...
<p><input type="radio" name="option" checked="checked" value="10" /></p> <p><input type="radio" name="option" value="20" /></p> <p><input type="radio" name="option" value="30" /></p> <input ...
<script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> ...
单选组radio: $(“input[@type=radio][@checked]”).val(); 单选组radio: $(“input[@type=radio]”).attr(“checked”,’2′);//设置value=2的项目为当前选中项 获取一组radio被选中项的值 var item = $(‘input...
代码如下: <tr> <th>是否映射:</th> <td> <input type=”radio” ...<label for=”no”>否</label> </td> </tr> 用jquery方法操作,使其默认选项是否. 代码如下: $(function () { var sfys = “<#if os??&Ⓢ.s
<form id=myform> <input type=radio value=1 name=gender>男 <input type=radio value=2 ...<div id=myText></div> 获取值方式一 < script src =js/jquery-3.3.1.min.js ></ script >
input type=radio name=payMethod value=1 />男 <input type=radio name=payMethod value=2 />女 </div> 获取一组单选按钮对象:var obj_payPlatform = $('#wrap input[name=payMethod]'); 获取被...
效果图: 是不是比默认的好看多了,个人的审美观应该还是可以的。 接下来我们一起来看看实现这款美化版Checkbox的源代码,主要思路是利用隐藏原来的...input type=radio name=radio-btn />Male </li> <li> <
1、总是使用#id去寻找element. 在jQuery中最快的选择器是ID选择器 ($(‘#someid’)). 这是因为它直接映射为JavaScript的...input type=radio class=on name=light value=red /> Red</li> <li><input
input type=radio id=male value=m name=sex/>男 <input type=radio id=female value=f name=sex/>女 <!--这里设置表单校验错误信息的显示位置--> <label class=error for=sex></label> </td> 2.2...
<label>aaaaaa</label> <input type=”checkbox” value=’2′ /><label>bbbbbb</label> <input type=”checkbox” value=’3′ /><label>ccccc</label> <input type=”checkbox” value=’4′ />...