jquery radio checkbox 取得选中值

[size=large]一、jquery取得radio、checkbox的选中值[/size]
几种取值方式:

<!-- 通过jquery的选择器指定name和checked进行取值 -->
$('input[name="testRadio"]:checked').val();
$('input:radio:checked').val();
$('input[@name="testRadio"][checked]');
$('input[name="testRadio"]').filter(':checked');
$('input[name="testRadio"]').each(function(){
alert(this.value);
});
$('input[name="testradio"]:eq(1)').val();


[size=large]二、事例[/size]

<HTML>
<HEAD>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
</HEAD>
<body>
<form name="testForm">
<input type="radio" name="testRadio" value="jquery_radio1" />jquery_radio1
<input type="radio" name="testRadio" value="jquery_radio2" checked="checked" />jquery_radio2
<input type="radio" name="testRadio" value="jquery_radio2" />jquery_radio3
<br />
<input type="checkbox" name="testCheckbox" value="sssss" />jquery_checkbox1
<input type="checkbox" name="testCheckbox" value="dddd" />jquery_checkbox2
<br />
<input type="button" value="jquery" onclick="test()"><br />


<!-- input 的属性autocomplete 默认为on 其含义代表是否让浏览器自动记录之前输入的值 很多时候,需要对客户的资料进行保密 -->
<input name="test1" type="text" value="123" autocomplete="off">
</form>
<script>
function test(sss) {
//alert(sss);
alert($('input[name="testRadio"]').filter(':checked').val());
alert($('input[name="testCheckbox"]:checked').val());
}
$(document).ready(function() {//ready begin
//$('input[name="testradio"]:checked').val();
});
</script>
</body>
</HTML>


[size=large]三、找不到function[/size]
找不到function不一定就是没有这个方法,也有可能是冲突引起的。
解决:form表单控件的ID或name,最好不和function名称有重复的,反之亦然。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值