全选卡

    xiaoxiao2022-07-07  206

    全选框

         全选功能:

             ·效果原理

             ·控制checkbox的状态--checked

             ·如何获取一组元素--getElementsByTagName

          for循环

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script> window.onload = function() { var oBtn = document.getElementById('btn'); var aInput=document.getElementsByTagName('input'); var i=0; oBtn.onclick = function () { for(i=0;i<aInput.length; i++){ aInput[i].checked=true; } } }; </script> </head> <body> <p id="btn">全选</p> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> </body> </html>

     

    最新回复(0)