| jQuery入门简介 |
1.精准简单的选择对象(dom): wy51JM http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") PiONA9 http://blog.numino.net/ $('.element');//Class tgUb0s http://blog.numino.net/ $('p');//html标签 umcCLc http://blog.numino.net/ $("form > input");//子对象 Cpmw2w http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 340ZmK http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 3HYyyS http://blog.numino.net/ $(":input");//表单对象 5llK3x http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 8aIGin http://blog.numino.net/ 2.对象函数的应用简单和不限制: b2DKWy http://blog.numino.net/ element.function(par); ylxUeA http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... 1iBU99 http://blog.numino.net/ 3.对已选择对象的操作(包括样式): Jdky82 http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 A2RozF http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 oWZxUX http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 Te8Ctd http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 fpQK4v http://blog.numino.net/ $("p").add("span");//给对象增加标签 h4ixhE http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 71F8Zx http://blog.numino.net/ $("p").parent();//对象的父级元素 0SML2G http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 Egt7YD http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp sYTYvX http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 VegJfj http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 HvEX9I http://blog.numino.net/ 5.对事件的支持: 1IMQrC http://blog.numino.net/ $("p").hover(function () { K15W8r http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 NPjCLB http://blog.numino.net/ }, function () { oG2nVp http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 tsFVm0 http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) CmWEi8 http://blog.numino.net/ 6.动画: jhtp9Z http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) o7708Y http://blog.numino.net/ $("#go").click(function(){ 7NQl6n http://blog.numino.net/ $("#block").animate({ Z0cQgG http://blog.numino.net/ width: "90%", TAtfuX http://blog.numino.net/ height: "100%", 2ycF1n http://blog.numino.net/ fontSize: "10em" u383JG http://blog.numino.net/ }, 1000 ); ATxbMa http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 vcDwqt http://blog.numino.net/ 7.扩展: OMcrJE http://blog.numino.net/ $.fn.background = function(bg){ rs0CS0 http://blog.numino.net/ return this.css('background', bg); c47J6O http://blog.numino.net/ }; 8cMe8d http://blog.numino.net/ $(#element).background("red"); WfCfoS http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) 928PjU http://blog.numino.net/
|
|