2016-06-07 189 views
0

我試圖在單擊按鈕時立即提醒「你好」。我在瀏覽器中得到了上面的錯誤,並且在下面的html中看到,我將腳本鏈接放在按鈕標籤下方,所以我不知道是什麼原因導致了錯誤。任何幫助表示讚賞。TypeError:無法讀取null屬性「removeAttribute」

receiver.js

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

的index.html

<!DOCTYPE html> 
 
\t <html> 
 
\t <head> 
 
\t <link href="public/stylesheets/style.css" rel="stylesheets" /> 
 
\t </head> 
 

 
\t <body> 
 
\t \t <button type="submit" id="passform"></button> 
 

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

+0

這可能與AdBlock extenstion有關,如http://stackoverflow.com/questions/38143879/cannot-read-property-removeattribute-of-null-cant-find-source-of-it –

回答

0

receiver.js文件明確提及ences 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>

+0

我試過了,它仍然不起作用 – Sparksido

+0

你確定你的jQuery文件實際上被正確加載嗎?嘗試在瀏覽器中使用開發工具(F12),並檢查控制檯或網絡選項卡中是否有任何錯誤。 –

+0

這可能是這種情況,但我不知道如何從我給出的錯誤中解碼,並且我從我的瀏覽器工具開始的錯誤 – Sparksido

0

你在Chrome上運行呢?它可能與AdBlock相關。嘗試將您的瀏覽器更改爲FireFox並查看是否收到相同的錯誤。

相關問題