標籤:round button javascrip alt name ble ext false click
1 <style type="text/css"> 2 table { 3 width: 800px; 4 text-align: left; 5 border-collapse: collapse; 6 } 7 8 td, th { 9 padding: 10px;10 border: 1px solid black;11 }12 </style>13 <script type="text/javascript">14 15 16 // 反選17 function choose(tag) {18 var inputs = document.getElementsByTagName("input");19 //全選20 for (var i = 0; i < inputs.length - 3; i++) {21 var inputNode = inputs[i];22 if (tag === 1) {23 if (!inputs[i].checked) {24 inputs[i].checked = true;25 }26 //全不選27 } else if (tag === -1) {28 if (inputNode.checked) {29 inputNode.checked = false;30 }31 } else {32 //反選33 inputs[i].checked = !inputs[i].checked;34 }35 }36 }37 </script>38 </head>39 <body>40 <table cellpadding="2" id="tableId">41 <tr>42 <th>43 選擇44 </th>45 <th>46 姓名47 </th>48 <th>49 年齡50 </th>51 </tr>52 <tr>53 <td>54 <label>55 <input type="checkbox">56 </label>57 </td>58 <td>59 張三60 </td>61 <td>62 1963 </td>64 </tr>65 <tr>66 <td>67 <input type="checkbox">68 </td>69 <td>70 李四71 </td>72 <td>73 1874 </td>75 </tr>76 <tr>77 <td>78 <input type="checkbox">79 </td>80 <td>81 張三82 </td>83 <td>84 1885 </td>86 </tr>87 <tr>88 <td colspan="3">89 <input type="button" onclick="choose(1)" value="全選">90 <input type="button" onclick="choose(-1)" value="全不選">91 <input type="button" onclick="choose(0)" value="反選">92 </td>93 </tr>94 </table>
js多選全選