【jQuery 学习笔记】初识jQuery
2014-07-25 15:04
471 查看
官方网站 <a target=_blank href="http://jquery.com/">http://jquery.com/</a>
下载页面 http://docs.jquery.com/Downloading_jQuery
基本使用
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src="jquery.js"></script> <script> </script> </body> </html>上述html代码简单的调用了jquery的js库没有做任何操作,主要src的路径要选择正确。
编写第一段jquery代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src=jquery.js> </script> <script> $(document).ready(function () { $("a").click(function (event) { alert("Thanks for visiting!"); }); }); </script> </body> </html>
在这段中调用了ready这个事件,这个事件是在整个页面加载完毕包括一些logo之后才进行的。在jQuery中有很多event(http://api.jquery.com/category/events/#ready.28_fn_.29)
$(document).ready(function(){ $("a").click(function(event){ alert("As you can see, the link no longer took you to jquery.com"); event.preventDefault(); }); });preventDefault操作可以把之前的默认的行为阻止掉
关于类
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>Demo</title> <style> a.test { font-weight: bold; } </style> </head> <body> <a href="http://jquery.com/">jQuery</a> <script src=jquery.js></script> <script> $("a").addClass("test"); </script> </body> </html>
在这段代码中用js为a加入了一个test的样式,移除用
$("a").removeClass("test");
相关文章推荐
- jQuery学习笔记1——初识jQuery
- jquery学习笔记----初识jquery
- Jquery 学习笔记(一)Jquery初识
- ASP Forum2.0学习笔记之一---初识default.aspx
- jQuery学习笔记 02
- JQuery学习笔记(六)
- jQuery 学习笔记(七)
- JQuery学习笔记(三)
- jQuery学习笔记 03
- jquery学习笔记-jquery结合showModalDialog实现子页面局部刷新父页面
- jQuery学习笔记 04
- JQuery学习笔记(四)
- jQuery学习笔记 08
- Python学习笔记一(初识Python)
- jquery学习笔记(二)
- jQuery学习笔记 06
- wpf学习笔记---初识xaml标签语言
- JQuery学习笔记(一)
- jQuery学习笔记(八)
- JQuery学习笔记 实现图片翻转效果和TAB标签切换效果第1/2页