JQuery Study Notes 學習筆記(一)

來源:互聯網
上載者:User

1. 使用jquery
  到jquery.com下載jquery.js目前的版本是1.4.2
  建立一個html頁面 複製代碼 代碼如下:<!DOCTYPE html><BR><html lang="en"><BR><head><BR> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><BR> <script type="text/javascript" src="<SPAN style="COLOR: #ff0000"><STRONG>jquery.js</STRONG></SPAN>"></script></PRE>
<PRE class=brush> <script type="text/javascript"><BR> <SPAN style="COLOR: #ff0000"> $(document).ready(function(){</SPAN><BR><SPAN style="COLOR: #ff0000"> $("a").click(function(event){</SPAN><BR><SPAN style="COLOR: #ff0000"> alert("As you can see, the link no longer took you to jquery.com");</SPAN><BR><SPAN style="COLOR: #ff0000"> event.preventDefault();</SPAN><BR><SPAN style="COLOR: #ff0000"> });</SPAN><BR><SPAN style="COLOR: #ff0000"> });</SPAN><BR> <BR> </script><BR></head><BR><body><BR> <a href="<A class="external free" href="http://jquery.com/">http://jquery.com/</A>">jQuery</a><BR></body><BR></html>

代碼解釋:
  $(document).ready(function(){...})在頁面載入完時添加function()函數內容
  $("a").click(function(event){...})設定a標籤的click事件函數
  event.preventDefault()阻止原事件執行
  代碼功能:點擊<a>標籤只彈出alert資訊後,頁面並不跳轉到http://jquery.com/。
2. 添加和移除HTML class
  首先在<head>中添加一些樣式,例如: 複製代碼 代碼如下:<style type="text/css">
a.test { font-weight: bold; }
</style>

在script中使用addClass和removeClass來添加和移除HTML class,例如: 複製代碼 代碼如下:$("a").addClass("test");//所有a標記粗體
$("a").removeClass("test");//取消所有a標記粗體

3.特效
  jQuery提供了一些非常方便的特效 複製代碼 代碼如下:$("a").click(function(event){
event.preventDefault();
$(this).hide("slow");
});

點擊<a>標籤後,標記慢慢消失
4.回調與函數
  無參數回調 複製代碼 代碼如下:$.get('myhtmlpage.html', myCallBack);

帶參數回調 複製代碼 代碼如下:$.get('myhtmlpage.html', function(){
myCallBack(param1, param2);
});

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.