jQuery導入及測試


jQuery導入:

<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>//將jQuery包引入HTML

<script>jQuery語句</script>//調用jQuery書寫jQuery程序

此處src為已經下載的jQuery文件安裝目錄。

jQuery測試:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
</script>
<script>
if(typeof jQuery == 'undefined'){
    window.alert("沒有jquery");
}
</script>
</head>
<body>
<p>如果您點擊我,我會消失。</p>
<p>點擊我,我會消失。</p>
<p>也要點擊我哦。</p>
</body>
</html>

  如果運行后界面上不彈出“沒有jquery”的提示以及段落被點擊后消失,則導入成功;否則說明沒有成功,那么就檢測代碼吧,一般將jQuery放入項目文件下應該是可以用的,不成功的話多數情況是代碼有問題,如某些拼寫錯誤等。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM