---
title: "jquery radio checkbox 取得选中值"
author: "langmnm"
date: "2014-07-29T15:40:12Z"
tags: []
categories: ["Web前端"]
slug: "jquery-radio-checkbox"
draft: false
lastmod: "2014-07-29T15:40:12Z"
id: 2097844
url: "https://langmnm.iteye.com/blog/2097844"
---

一、jquery取得radio、checkbox的选中值
几种取值方式：

```js

<!-- 通过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();

```


二、事例

```html

<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>

```


三、找不到function
找不到function不一定就是没有这个方法，也有可能是冲突引起的。
解决：form表单控件的ID或name，最好不和function名称有重复的，反之亦然。