<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> window.onload = function(){ var list = document.getElementById("list"); var inputs = document.getElementsByTagName("input"); var ok = document.getElementById("ok"); var ret = document.getElementById("ret"); ok.onclick = function(){ var count = 0; for(var i = 0;i< inputs.length;i++){ if(inputs[i].checked){ count ++; } } if(count > 0){ ret.innerHTML = "已经选择"+count; ret.style.display = ‘block‘; } else{ ret.innerHTML = " "; ret.style.display = none; } } } </script> </head> <body> <ul id="list"> <li><label><input type="checkbox"/>1</label></li> <li><label><input type="checkbox"/>2</label></li> <li><label><input type="checkbox"/>3</label></li> <li><label><input type="checkbox"/>4</label></li> <li><label><input type="checkbox"/>5</label></li> </ul> <button id="ok">确定</button> <p id="ret" style="display: none"></p> </body> </html>
时间: 2024-10-06 13:16:41