首页 > 代码库 > DOM用TagName操作标签

DOM用TagName操作标签

 

 

 

 1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4     <title>通过ID获取值</title> 5    6     <script type="text/javascript"> 7         function intevent() 8         { 9             //这个初始化是为每一个input的按钮加入了onclick事件10             var inputs = document.getElementsByTagName("input");11             for(var i=0;i<inputs.length;i++)12             {13                 var input = inputs[i];14                 input.onclick = btnclick;15                16             }17         }18         function btnclick()19         {20             var inputs = document.getElementsByTagName("input");21             for (var i = 0; i < inputs.length; i++) {22                 var input = inputs[i];23                 if(input==window.event.srcElement)24                 {25                     input.value = "http://www.mamicode.com/呜呜";26                 }27 28                 else29                 {30                     input.value = http://www.mamicode.com/‘laugh‘;31                 }32 33             }34         }35     </script>36 </head>37 <body onl oad="intevent()">38     <input type="button" value="http://www.mamicode.com/laugh" />39     <input type="button" value="http://www.mamicode.com/laugh" />40     <input type="button" value="http://www.mamicode.com/laugh" />41     <input type="button" value="http://www.mamicode.com/laugh" />42     <input type="button" value="http://www.mamicode.com/laugh" />43     <input type="button" value="http://www.mamicode.com/laugh" />44 </body>45 </html>

 

DOM用TagName操作标签