[英]JavascriptExecutor: Cannot read property 'removeAttribute' of null
[英]TypeError: Cannot read property “removeAttribute” of null
单击按钮后,我试图提醒“您好”。 我在浏览器中收到上述错误,并且如下面的html所示,我将脚本链接放在button标记下方,所以我不知道是什么原因导致了错误。 任何帮助表示赞赏。
receiver.js
$(function(){ $("#passform").click(function(){ alert("hello"); console.log("hello"); }); });
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>
您的receiver.js
文件显然引用了jQuery,因此依赖于jQuery。 因此,在引用依赖它的其他文件之前,您需要确保先引用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>
除此之外,我看不到任何代码会明确引用removeAttribute()
函数,因此示例中缺少一些代码,或者某些脚本无法正确加载。
例
<!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>
您在chrome上运行吗? 可能与AdBlock有关。 尝试将浏览器更改为FireFox,看看是否遇到相同的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.