简体   繁体   English

TypeError:无法读取null的属性“ removeAttribute”

[英]TypeError: Cannot read property “removeAttribute” of null

I'm trying to alert "hello" as soon as a button is clicked. 单击按钮后,我试图提醒“您好”。 I get the error above on my browser, and as seen in the html below, I put the script link below the button tag so I don't know what causes the error. 我在浏览器中收到上述错误,并且如下面的html所示,我将脚本链接放在button标记下方,所以我不知道是什么原因导致了错误。 Any help is appreciated. 任何帮助表示赞赏。

receiver.js receiver.js

 $(function(){ $("#passform").click(function(){ alert("hello"); console.log("hello"); }); }); 

index.html index.html

 <!DOCTYPE html> <html> <head> <link href="public/stylesheets/style.css" rel="stylesheets" /> </head> <body> <button type="submit" id="passform"></button> <script type="scripi/javascript" src="C:/users/owner/desktop/steelVault/public/javascripts/receiver.js"></script> <script type="scripi/javascript" src="C:/users/owner/desktop/steelVault/public/javascripts/jquery/jquery-2.2.4.min.js"></script> </body> </html> 

Your receiver.js file clearly references jQuery and thus depends on it. 您的receiver.js文件显然引用了jQuery,因此依赖于jQuery。 As such, you'll need to ensure that you reference jQuery prior to referencing your other files that depend on it : 因此,在引用依赖它的其他文件之前,您需要确保先引用jQuery:

<script type="script/javascript" src="C:/users/owner/desktop/steelVault/public/javascripts/jquery/jquery-2.2.4.min.js"></script>
<script type="script/javascript" src="C:/users/owner/desktop/steelVault/public/javascripts/receiver.js"></script>

Besides this, I don't see any code that would explicitly reference the removeAttribute() function, so there is some code missing from the example or an issue with some of the scripts not loading properly. 除此之外,我看不到任何代码会明确引用removeAttribute()函数,因此示例中缺少一些代码,或者某些脚本无法正确加载。

Example

 <!DOCTYPE html> <html> <head> <!-- Omitted --> </head> <body> <button type="submit" id="passform"></button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(function() { $("#passform").click(function() { alert('hello'); console.log('hello'); }); }); </script> </body> </html> 

Are you running this on chrome? 您在chrome上运行吗? It could be related to AdBlock. 可能与AdBlock有关。 Try changing your browser to FireFox and see if you're getting the same error. 尝试将浏览器更改为FireFox,看看是否遇到相同的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM