• 获取DOM元素的三种方法


     1 <!doctype html>
     2 <html lang="en">
     3  <head>
     4   <meta charset="UTF-8">
     5   <meta name="Generator" content="EditPlus®">
     6   <meta name="Author" content="">
     7   <meta name="Keywords" content="">
     8   <meta name="Description" content="">
     9   <title>获取DOM元素的三种方法</title>
    10  </head>
    11  <body onload="getElement()">
    12     <script type="text/javascript">
    13         function getElement(){
    14             //getElementsByTagName根据标签名
    15             var a=document.getElementsByTagName("input")
    16             alert(a.length)//4
    17             //getElementsByName根据name值
    18             var b=document.getElementsByName("aihao")
    19             alert(b.length)//3
    20             //getElementById根据id值
    21             var c=document.getElementById("c")
    22             alert(c.value)
    23 
    24         }
    25     </script>
    26     <input type="checkbox" name="aihao" value="001">抽烟<br>
    27     <input type="checkbox" name="aihao" value="002">喝酒<br>
    28     <input type="checkbox" name="aihao" value="003">烫头<br>
    29     <input type="text" id="c" name="c" value="004">
    30   
    31  </body>
    32 </html>
  • 相关阅读:
    定时器
    SysTick
    13.看门狗
    12.FSMC
    11.中断
    ##HTML行内块元素好迷啊!!
    ##HTML基础
    ##CS3动画效果
    ##管家婆项目(tools层)
    ##管家婆项目(app层)
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/8492096.html
Copyright © 2020-2023  润新知