標籤:selector 符號 rip nbsp 新版本 語言 span 點擊 應該
一、如何把 jQuery 添加到網頁
<script> 標籤應該位於頁面的 <head> 部分。
<head><script src="jquery.js"></script></head>
在html5中,因為JavaScript 是 HTML5 以及所有現代瀏覽器中的預設指令碼語言!<script> 標籤中不需要使用 type="text/javascript",當然如果不是的話還是加上比較好~
<head><script src="jquery.js" type="text/javascript"></script></head>
jquery.js需要在官網下載,最好下載當前最新版本
二、jQuery文法
jQuery 文法是為 HTML 元素的選取編製的,可以對元素執行某些操作。
基礎文法是:$(selector).action()
- 貨幣符號定義 jQuery
- 選擇符(selector)“查詢”和“尋找” HTML 元素
- jQuery 的 action() 執行對元素的操作
樣本:示範 jQuery hide() 函數
$(this).hide() - 隱藏當前元素
$("p").hide() - 隱藏所有段落
$(".test").hide() - 隱藏所有 class="test" 的所有元素
$("#test").hide() - 隱藏所有 id="test" 的元素
樣本:隱藏 id="text" 的元素
<script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("#button").hide(); }); });</script>
<p id="text">這是一段點擊就會隱藏的文字.</p><button type="button">按鈕</button>
所有 jQuery 函數位於一個 document ready 函數中:
$(document).ready(function(){--- jQuery functions go here ----});
這是為了防止文檔在完全載入(就緒)之前運行 jQuery 代碼。
[2016-10-24]jQuery學習回顧筆記1.0