[2016-10-24]jQuery學習回顧筆記1.0

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.