js 要求能够弹出对话框提示当前选中的是哪几个复选框

<html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>今日图灵IT培训</title> <body> 完成turing函数的内容,要求能够弹出对话框提示当前选中的是哪几个复选框。 <!--完成turing函数的内容,要求能够弹出对话框提示当前选中的是哪几个复选框。--> <form name="form1" onsubmit="return turing();"> <input type="checkbox" name="checker"/> 1 <input type="checkbox" name="checker"/> 2 <input type="checkbox" name="checker"/> 3 <input type="checkbox" name="checker"/> 4 <input type="checkbox" name="checker"/> 5 <input type="checkbox" name="checker"/> 6 <input type="submit"/> </form> </body> </html> <script> function turing() { // 在此处添加代码 } </script>

第1个回答  2014-06-20
<html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>今日图灵IT培训</title> <body> 完成turing函数的内容,要求能够弹出对话框提示当前选中的是哪几个复选框。 <!--完成turing函数的内容,要求能够弹出对话框提示当前选中的是哪几个复选框。--> <!--我在checkbox中加入了value 方便去提交值。--> <form name="form1" onsubmit="return turing();"> <input type="checkbox" name="checker" value="1"/> 1 <input type="checkbox" name="checker" value="2"/> 2 <input type="checkbox" name="checker" value="3"/> 3 <input type="checkbox" name="checker" value="4"/> 4 <input type="checkbox" name="checker" value="5"/> 5 <input type="checkbox" name="checker" value="6"/> 6 <input type="submit"/> </form> </body> </html> <script> function turing() { var checkboxes = document.getElementsByName("checker") var selected= "" var count=0 for(var i=0;i<checkboxes.length;i++){ if(checkboxes[i].checked){ count++; selected+=checkboxes[i].value+" " } } if(count==0){ alert("你没有选择复选框") return false } alert("你选择了"+count+"个复选框,分别是:"+selected) } </script>

求采纳本回答被提问者采纳
相似回答