使用document.ElementByTagName獲取input元素並添加事件

<input type="button" value="input" id="myInput">
window.onload=function (){
    document.getElementsByTagName('input')[0].onclick = function(e){
           alert("hello ");      
    }
}
我自己犯得錯誤
1:把onclick寫成了onClick(好久沒有寫原生了)
2:直接document.getElementsByTagName('input').onclick ...
  (因爲document.getElementsByTagName獲取的是dom列表,所以必須要有索引)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章