html中在后台用什么方法获得前台 checkbox 的值,判断是否被选中
2个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript">
function test (){
var names = document.getElementsByName("checkBoxName");
for( i = 0 ; i <names.length; i ++){
if (names[i].checked)
alert("This"+(i+1)+" was checked !----------------"+names[i].value);
else
alert("nothing");
}
}
function loadInfo(){
var valueStr = "aaaaa,cccc";
var values = valueStr.split(",");
var names = document.getElementsByName("checkBoxName");
for ( j = 0 ; j < values.length; j++ )
{
for( i = 0 ; i <names.length; i ++){
if (names[i].value==values[j])
names[i].checked="checked";
}
}
}
</script>
</HEAD>
<BODY onload="loadInfo();">
<input type="checkBox" name="checkBoxName" value="aaaaa"/>aaaaaa
<input type="checkBox" name="checkBoxName" value="aaaccc"/>aaaccc
<input type="checkBox" name="checkBoxName" value="cccc"/>cccc
<input type="button" value=" test " onclick="test();">
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript">
function test (){
var names = document.getElementsByName("checkBoxName");
for( i = 0 ; i <names.length; i ++){
if (names[i].checked)
alert("This"+(i+1)+" was checked !----------------"+names[i].value);
else
alert("nothing");
}
}
function loadInfo(){
var valueStr = "aaaaa,cccc";
var values = valueStr.split(",");
var names = document.getElementsByName("checkBoxName");
for ( j = 0 ; j < values.length; j++ )
{
for( i = 0 ; i <names.length; i ++){
if (names[i].value==values[j])
names[i].checked="checked";
}
}
}
</script>
</HEAD>
<BODY onload="loadInfo();">
<input type="checkBox" name="checkBoxName" value="aaaaa"/>aaaaaa
<input type="checkBox" name="checkBoxName" value="aaaccc"/>aaaccc
<input type="checkBox" name="checkBoxName" value="cccc"/>cccc
<input type="button" value=" test " onclick="test();">
</BODY>
</HTML>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询