js获取checkbox值
<html>
<head>
<script type="text/javascript">
function BatchDelete(){
var count = 0;
var a="";
if(document.datafrm.Sort.length)
{
for(var i = 0; i < document.datafrm.Sort.length; i++)
{
if(document.datafrm.Sort[i].checked)
{
a += document.datafrm.Sort[i].value + ';';
count++;
}
}
}
else {
if(document.datafrm.Sort.checked)
{
a += document.datafrm.Sort.value ;
}
}
if( count > 0)
{
if( confirm('是否要删除所选择的'+ count +'条记录!') )
{
alert(a);
//SubmitData(9);
}
}
else
{
alert('请在需要删除的条目前打勾!');
}
}
</script>
</head>
<body>
<form name="datafrm" method="post" id="datafrm">
<input name="Sort" type="checkbox" id="Sort1" value="1">原料
<input name="Sort" type="checkbox" id="Sort2" value="2">成品
<input name="Sort" type="checkbox" id="Sort3" value="石坯">石坯
<input name="Sort" type="checkbox" id="Sort4" value="饰品">饰品
<input name="Sort" type="checkbox" id="Sort5" value="机械配件">机械配件
<input name="Sort" type="checkbox" id="Sort6" value="其它">其它
<input name="ss" type="button" value="测试" onclick="BatchDelete()" />
</form>
</body>
</html>
代码
用js实现多选框的复选
<html>
<head>
<script type="text/javascript">
function check()
{
var arr = new Array();//定义数组
arr = document.getElementById("on");//取到tbody对象
index = arr.childNodes[0].childNodes //取到第一个结点的子结点
for(i=0;i<index.length;i++){
index[i].childNodes[0].checked = true; //循环设置每个结点中checkbox的checked
}
}
</script>
</head>
<body>
<form>
<table >
<tbody id="on">
<tr>
<td><input type="checkbox" id="check1" /></td>
<td><input type="checkbox" id="check1" /></td>
<td><input type="checkbox" id="check1" /></td>
<td><input type="checkbox" id="check1" /></td>
</tr>
</tbody>
</table>
<input type="button" onclick="check()" value="Check Checkbox" />
<input type="button" onclick="uncheck()" value="Uncheck Checkbox" />
</form>
</body>
</html>
请教一个JS获取多选框值的问题
<script type="text/javascript">
function qq () {
var str = ""
var a = document.form1.getElementsByTagName("input")
for(i=0;i<a.length;i++) {
if(a[i].type=="checkbox" && a[i].checked) {
str += a[i].value + ","
}
}
javascript:window.open('tiqu.asp?n='+str,'','width=700,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');
return false;
}
</script>
<form name="form1" method="post" action="">
<label>
<input name="userid" type="checkbox" id="userid" value="334" />
<br />
<input name="userid" type="checkbox" id="userid" value="123" />
<br/>
</label>
<a href="#" onclick="qq()">asdfasdf</a>
</form>