複選框取值.html
阿新 • • 發佈:2019-02-20
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>My JSP 'hello.jsp' starting page</title> </head> <script type="text/javascript"> //頁面取到選中的值 function check_black() { var blackName = document.getElementsByName("black"); for(var i = 0; i < blackName.length; i++) { if(blackName[i].checked == true) { var a = blackName[i].value; alert(a); } } } </script> <body> <form action="" method="post" name = "form"> <input type="checkbox" name = "black" value = "1">打籃球 <input type="checkbox" name = "black" value = "2">看電視 <input type="checkbox" name = "black" value = "3">游泳 <input type="checkbox" name = "black" value = "4">爬山 <input type="checkbox" name = "black" value = "5">唱歌 <input type = "submit" name = "tijiao" value = "提交" onclick="check_black();"> </form> </body> </html>