日期:2014-05-16 浏览次数:20557 次
function getval(){
var v=$('input[id="bh"]:checked').map(function(){return this.value}).get().join(',');
alert(v)
}
function putval(){
var arg=arguments;
$('input[id="bh"]').each(function(idx,el){
this.value=arg[idx]
});
}
<html>
<head>
<title>测试form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function getval(){
var arr = [];
$("#div1 :checkbox").each(function(){
arr.push(this.value);
});
alert("所有checkbox的值分别为:"+arr.join(","));
}
function putval(va,vb,vc){
var arr = [va,vb,vc];
$("#div1 :checkbox").each(function(index){
if(index>2)
return false;
$(this).val(arr[index]);
});
}
</script>
</head>
<body>
<div id="div1" >
<input type="checkbox" id="bh" value="a">
<input type="checkbox" id="bh" value="b">
<input type="checkbox" id="bh" value="c">
<input type="button" value="btn1" value="取值" onclick="getval();">