1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript" src="../jQuery/jquery-3.5.1.min.js"></script> <script type="text/javascript"> $(function () { $("#checkAll").click(function () { $("#check>input").prop("checked", true); $("#AllOrAllNot").prop("checked", true); })
$("#checkAllNot").click(function () { $("#check>input").prop("checked", false); $("#AllOrAllNot").prop("checked", false); })
$("#checkRev").click(function () { $("#check>input").each(function () { this.checked = !this.checked; }) let len = $("#check>input").length; let checkLen = $("#check>input:checked").length; $("#AllOrAllNot").prop("checked", len === checkLen); })
$("#post").click(function () { let msg = "喜欢的游戏为:"; $("#check>input:checked").each(function () { msg = msg + '\n' + this.value; }) alert(msg); })
$("#check>input").click(function () { let len = $("#check>input").length; let checkLen = $("#check>input:checked").length; $("#AllOrAllNot").prop("checked", len === checkLen); }) }) </script> </head> <body> <form> 喜欢的游戏为:<input type="radio" id="AllOrAllNot"/>全选/全不选 <div id="check"> <input type="checkbox" value="怪物猎人"/> 怪物猎人 <input type="checkbox" value="合金装备"/> 合金装备 <input type="checkbox" value="孤岛惊魂"/> 孤岛惊魂 <input type="checkbox" value="耻辱"/> 耻辱 </div> <div> <input type="button" id="checkAll" value="全选" /> <input type="button" id="checkAllNot" value="全不选"/> <input type="button" id="checkRev" value="反选" /> <input type="button" id="post" value="提交" /> </div> </form> </body> </html>
|