abstrait:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title&g
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> .big{width: 200px;height: auto;border: 1px solid #000;margin: 20px auto;text-align: center} .big input{margin: 10px;} </style> <script type="text/javascript"> function checkAll() { var all = document.getElementById('first_in');//獲取 var one = document.getElementsByName('item');//通過獲取name對(duì)應(yīng)的input元素,可得到input的數(shù)量(前提是name值全都一樣) var x = 0;//getElementsByName獲取到的是數(shù)組,所以要加[];x充當(dāng)下標(biāo) while (x < one.length){ if (all.checked){ one[x].checked = true; } else { one[x].checked = false; } x++; } } </script> </head> <body> <div class="big"> <input type="checkbox" id="first_in" onclick="checkAll()" lick><lable for="first_in">全選</lable><hr> <input type="checkbox" name="item">選項(xiàng)1<hr> <input type="checkbox" name="item">選項(xiàng)2<hr> <input type="checkbox" name="item">選項(xiàng)3<hr> <input type="checkbox" name="item">選項(xiàng)4<hr> <input type="checkbox" name="item">選項(xiàng)5<hr> <input type="checkbox" name="item">選項(xiàng)6<hr> <input type="checkbox" name="item">選項(xiàng)7<hr> <input type="checkbox" name="item">選項(xiàng)8 </div> </body> </html>
Professeur correcteur:查無此人Temps de correction:2019-03-26 09:12:58
Résumé du professeur:完成的不錯(cuò)。js的標(biāo)簽獲取,需要多練習(xí),這個(gè)很重要,繼續(xù)加油。