<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=”提交” />

自由转载,转载请注明: 转载自WEB开发笔记 www.chhua.com

本文链接地址: JS 判断复选框是否选中并取出值 http://www.chhua.com/web-note144

相关笔记

更多