jquery获取radio值实例

2019-12-21,,,,,

本文实例讲述了jquery获取radio的方法,分享给大家供大家参考。具体如下:

单选组radio: 复制代码 代码如下:$("input[@type=radio][@checked]").val();

单选组 radio: 复制代码 代码如下:$("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项

获取一组radio被选中项的值
复制代码 代码如下:var item = $('input[@name=items][@checked]').val();

radio单选组的第二个元素为当前选中值
复制代码 代码如下:$('input[@name=items]').get(1).checked = true

jquery老的版本
复制代码 代码如下:var_name = $("input[@name='radio_name']:checked").val();
jquery 1.3以后的版本
复制代码 代码如下:var_name = $("input[name='radio_name']:checked").val();

获取radio值的jquery实例:

复制代码 代码如下:function getra(){

var_name = $("input[name='isspecialcnt']:checked").val();
//alert(var_name);
if(var_name=='1'){
$("#isspecialcntyes").show();
$("#isspecialcntno").hide();
}
if(var_name=='0'){
$("#isspecialcntyes").hide();
$("#isspecialcntno").show();
}
}

<form name="form1" method="post" action="">
<p>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_0">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_1">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_2">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_3">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_4">
单选</label>
<br>
<label>
<input type="radio" name="radiogroup1" value="单选" id="radiogroup1_5">
单选</label>
<br>
</p>
</form>

希望本文所述对大家的javascript程序设计有所帮助。

您可能感兴趣的文章:

  • jQuery根据ID获取input、checkbox、radio、select的示例
  • jQuery中的RadioButton,input,CheckBox取值赋值实现代码
  • jQuery操作input type=radio的实现代码
  • jQuery插件datalist实现很好看的input下拉列表
  • jQuery判断多个input file 都不能为空的例子
  • jQuery多个input求和的实现方法
  • JQuery控制radio选中和不选中方法总结
  • JQuery判断radio(单选框)是否选中和获取选中值方法总结
  • jquery中radio checked问题
  • jquery单选框radio绑定click事件实现方法
  • 利用jquery操作Radio方法小结
  • jquery获取radio值(单选组radio)
  • jQuery 操作input中radio的技巧

《jquery获取radio值实例.doc》

下载本文的Word格式文档,以方便收藏与打印。