`

Uncaught TypeError: Cannot set property 'onclick' of null

 
阅读更多

<html>                                                                 
 <head>                                                                                             
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">                            
 <title>ϵͳ</title>      
         <script type="text/javascript">
document.getElementById("btn").onclick=function(){alert("214")};
</script>                                                                  
<body>
<input type="button" id="btn" name="name" value="11">                                                                                                   
     </body>  
    </html>

 

=======================================

解决方案

1,    <script type="text/javascript">
document.getElementById("btn").onclick=function(){alert("214")};
</script>   放input框后

2,让其自动加载

window.onload=function(){}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics