日期:2014-05-19 浏览次数:20772 次
var arr = new Array();
var test = $("input[name^='test']").each(function(){
arr.push($(this).val());
})
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript" src="/js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('input[name=t]').click(function(){
//获取的本来就是数组,你要获取数组的数值就需要遍历
$("input[name*='test']").each(function(){
alert($(this).val());
});
});
});
</script>
</head>
<body>
<input type="button" name="t" value="test">
<br>
<input name="test1" value="a"/>
<input name="test2" value="b"/>
<input name="test3" value="c"/>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery</title>
<script language="javascript" type="text/javascript"
src="Jscript/jquery-1.4.2.min.js"></script>
<style type="text/css">
body{font-size:12px;text-align:left}