<title>javaScript 获取复选框的值</title>
<script>
function checkbox()
{
var str=document.getElementsByName("box");
var objarray=str.length;
var chestr="";
for (i=0;i<objarray;i++)
{
if(str[i].checked == true)
{
chestr+=str[i].value+",";
}
}
if(chestr == "")
{
alert("请先选择复选框~!");
}
else
{
alert("复选框的值是:"+chestr);
}
}
</script>
选择您的拿手技术:
<input type="checkbox" name="box" id="box1" value="asp" />ASP
<input type="checkbox" name="box" id="box2" value="php" />PHP
<input type="checkbox" name="box" id="box3" value="jsp" />JSP
<input type="button" name="button" id="button" onclick="checkbox()" value="提交" />