JQuery Study Notes 學習筆記(一)
更新時間:2010年08月04日 02:03:10 作者:
jquery是當前比較流行的js類庫,學習它可以實現(xiàn)很多功能。
1. 使用jquery
到j(luò)query.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" >jQuery</a><BR></body><BR></html>
代碼解釋:
$(document).ready(function(){...})在頁面加載完時添加function()函數(shù)內(nèi)容
$("a").click(function(event){...})設(shè)置a標簽的click事件函數(shù)
event.preventDefault()阻止原事件執(zhí)行
代碼功能:點擊<a>標簽只彈出alert信息后,頁面并不跳轉(zhuǎn)到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.回調(diào)與函數(shù)
無參數(shù)回調(diào)
$.get('myhtmlpage.html', myCallBack);
帶參數(shù)回調(diào)
$.get('myhtmlpage.html', function(){
myCallBack(param1, param2);
});
到j(luò)query.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" >jQuery</a><BR></body><BR></html>
代碼解釋:
$(document).ready(function(){...})在頁面加載完時添加function()函數(shù)內(nèi)容
$("a").click(function(event){...})設(shè)置a標簽的click事件函數(shù)
event.preventDefault()阻止原事件執(zhí)行
代碼功能:點擊<a>標簽只彈出alert信息后,頁面并不跳轉(zhuǎn)到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.回調(diào)與函數(shù)
無參數(shù)回調(diào)
復制代碼 代碼如下:
$.get('myhtmlpage.html', myCallBack);
帶參數(shù)回調(diào)
復制代碼 代碼如下:
$.get('myhtmlpage.html', function(){
myCallBack(param1, param2);
});
相關(guān)文章
jQuery插件FusionCharts繪制2D柱狀圖和折線圖的組合圖效果示例【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts繪制2D柱狀圖和折線圖的組合圖效果,結(jié)合完整實例形式分析了jQuery使用插件FusionCharts載入xml格式數(shù)據(jù)繪制柱狀圖與折線圖組合圖效果的操作步驟與相關(guān)實現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-04-04jquery.form.js實現(xiàn)將form提交轉(zhuǎn)為ajax方式提交的方法
這篇文章主要介紹了jquery.form.js實現(xiàn)將form提交轉(zhuǎn)為ajax方式提交的方法,涉及jQuery插件實現(xiàn)form表單的Ajax提交技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04Query中click(),bind(),live(),delegate()的區(qū)別
這篇文章主要介紹了Query中click(),bind(),live(),delegate()之間的區(qū)別。需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11