| jQuery入门简介 |
1.精准简单的选择对象(dom): 76pLyv http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") oDhqxs http://blog.numino.net/ $('.element');//Class ntvns9 http://blog.numino.net/ $('p');//html标签 rx9gqK http://blog.numino.net/ $("form > input");//子对象 91PRRh http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 G3W3jH http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 8jwTwi http://blog.numino.net/ $(":input");//表单对象 BaO11K http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 2GOvwZ http://blog.numino.net/ 2.对象函数的应用简单和不限制: C1plAH http://blog.numino.net/ element.function(par); 6OUJg6 http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... nLD6vY http://blog.numino.net/ 3.对已选择对象的操作(包括样式): 2NS33c http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 rdD47s http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 88yi2J http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 B2gs5K http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 EO4Muf http://blog.numino.net/ $("p").add("span");//给对象增加标签 i4N7BM http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 tSXA81 http://blog.numino.net/ $("p").parent();//对象的父级元素 zD6d7C http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 q3in9y http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp aZx8D4 http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 Mga5XF http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 Rgv5fJ http://blog.numino.net/ 5.对事件的支持: 5ZCT3I http://blog.numino.net/ $("p").hover(function () { wN2Z4U http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 6PJK4K http://blog.numino.net/ }, function () { JlcC0P http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 eZ6r3x http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) l920Gx http://blog.numino.net/ 6.动画: d5ubzI http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) hyrh78 http://blog.numino.net/ $("#go").click(function(){ BI03RM http://blog.numino.net/ $("#block").animate({ v39s7h http://blog.numino.net/ width: "90%", pUk976 http://blog.numino.net/ height: "100%", xF6h9v http://blog.numino.net/ fontSize: "10em" 18bVvl http://blog.numino.net/ }, 1000 ); f01xhF http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 NekQsy http://blog.numino.net/ 7.扩展: JGn35D http://blog.numino.net/ $.fn.background = function(bg){ P0ihtq http://blog.numino.net/ return this.css('background', bg); 0rkLh8 http://blog.numino.net/ }; gbgaLw http://blog.numino.net/ $(#element).background("red"); 6LAM38 http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) 8UFu11 http://blog.numino.net/
|
|