簡體   English   中英

TypeError:無法讀取null的屬性“ removeAttribute”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM