如何通过Jquery获取radio的值
Jquery老的版本
var_name = $(“input[@name='radio_name']:checked”).val();
Jquery 1.3以后的版本
var_name = $(“input[name='radio_name']:checked”).val();
区别是老版本有个@.
myCode:
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();
}
}
<tr>
<td class="dataTable_deatil_title">是否特殊箱</td>
<td>
<s:radio name="isSpecialCnt" list="#application.optionsService.makeParamMap()" onclick="getra()"> </s:radio>
</td>
<td class="dataTable_deatil_title">开航日期</td>
<td><s:textfield id="sailingDay" name="sailingDay" size="10"
value="%{departureDate == null ? '' : getText('global.format.date',{sailingDay})}" />
<img id="img_sailingDay"
src="<c:url value="/widgets/calendar/images/calendar.gif"/>"
width="22" height="19" align="absmiddle" /></td>
</tr>
<tr id="isSpecialCntYes" style="display:none">
<td class="dataTable_deatil_title">柜型</td>
<td><s:select name="specialCntType" list="#application.optionsService.getParamsOptions('PTL_TRADE_CNTTYPE')" headerKey=""
headerValue="%{getText('option.empty.text')}"></s:select></td>
</tr>
<tr id="isSpecialCntNo" style="display:none">
<td class="dataTable_deatil_title">柜型</td>
<td><s:textfield name="specialCntType" /></td>
</tr>
多选的值加起来?算术加?变成数组?字符串连接?
算术加:
var s = 0;
$(':checkbox:checked').each(function(i, n) { s += new Number(n.value); });
window.alert("结果为:" + s);
变成数组:
var s = [];
$(':checkbox:checked').each(function(i, n) { s[s.length] = n.value; });
window.alert("结果为:" + s.join()); // s 为值数组,不能直接输出,连接后输出为“值1,值2,...”
今天做项目的时候写单选,发觉input radio的可以多选,之前都没留意过,还以为自己的win8傻了,因为装了win8这两个星期来总是有些问题。
< div class = "bottom" >
< input type = "radio" name = "1" value = "1" />公开(署名)
< input type = "radio" name = "2" value = "2" />公开(匿名)
< input type = "radio" name = "3" value = "3" />私密
< a href = "#" class = "form_btn_2 fr mt20" title = "发表" alt = "发表" ></ a >
</ div >
|
后来才觉,不是win8傻,是自己傻了,同一组的单选的name值要一致。
< div class = "bottom" >
< input type = "radio" name = "1" value = "1" />公开(署名)
< input type = "radio" name = "1" value = "2" />公开(匿名)
< input type = "radio" name = "1" value = "3" />私密
< a href = "#" class = "form_btn_2 fr mt20" title = "发表" alt = "发表" ></ a >
</ div >
|
把input 的name值改过来就可以啦。就此记过,表示自己曾经无知过。
分享到:
相关推荐
jQuery美化radio和checkbox jQuery美化radio和checkbox jQuery美化radio和checkbox jQuery美化radio和checkbox
利用Jquery实现的自定义美化radio与checkbox,好东西赶紧下的额。
jquery的easyUI框架,单选按钮插件封装
JQuery操作checkbox、radio等示例
Jquery判断radio是否有选中,获取选中的值, 测试有效。兼容各浏览器。非常好用。
昨天网上找了很多关于设置select checkbox radio只读的,都没办法满足要求,自己写了一个
jquery操作Radio、Checkbox、Select详细Demo
jQuery中如何判断radio选中,这里共有4中方法来实现。
、根据原有的select 模拟生成新的 select。 2、支持键盘,可通过键盘选择选项。 3、可自定义样式。 4、方便灵活,可选择需要的seletc 进行模拟(非全局模拟) 5、判断用户是否开启脚本支持,若未开启,不进行...
先给大家分享一篇关于Jquery获取radio选中的值的实例内容 Jquery获取radio选中值实例总结 https://www.jb51.net/article/154831.htm 话不多说,请看代码: <!DOCTYPE ...
JQuery对radio的操作 (01).zip
单选组radio: $(“input[@type=radio][@checked]”).val(); 单选组radio: $(“input[@type=radio]”).attr(“checked”,’2′);//设置value=2的项目为当前选中项 获取一组radio被选中项的值 var item = $(‘input...
本文实例讲述了jquery判断单选按钮radio是否选中的方法。分享给大家供大家参考。具体如下: html代码如下: <input type="radio" id="d1" name="ra" value="a" checked="checked" /> <input type="radio" ...
在本篇文章里小编给大家分享了关于Jquery获取radio选中值实例总结内容,有兴趣的朋友们可以学习下。
jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码...
jquery取radio单选按钮的值[文].pdf
关于jquery的资料关于jquery的资料关于jquery的资料关于jquery的资料
主要介绍了JQuery控制Radio选中方法,涉及jQuery表单操作及鼠标事件响应的方法,需要的朋友可以参考下