| jQuery入门简介 |
1.精准简单的选择对象(dom): vOjDx1 http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") uXevWG http://blog.numino.net/ $('.element');//Class 2a3bra http://blog.numino.net/ $('p');//html标签 VE5aUF http://blog.numino.net/ $("form > input");//子对象 j8uvLU http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 yM4yh8 http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 iNo4db http://blog.numino.net/ $(":input");//表单对象 aAT5Er http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 g4IpsK http://blog.numino.net/ 2.对象函数的应用简单和不限制: vPATgm http://blog.numino.net/ element.function(par); yaCV4o http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... eZxzXK http://blog.numino.net/ 3.对已选择对象的操作(包括样式): yOvsUH http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 NcYbc4 http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 aGp2w8 http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 6vx9tr http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 594FGH http://blog.numino.net/ $("p").add("span");//给对象增加标签 J8MFSN http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 0G7KSW http://blog.numino.net/ $("p").parent();//对象的父级元素 RNXQXr http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 cIR52G http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp ckC9Ki http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 V6OiKq http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 0gcwmn http://blog.numino.net/ 5.对事件的支持: qmpt42 http://blog.numino.net/ $("p").hover(function () { baRCvt http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 q8r1Ou http://blog.numino.net/ }, function () { 1wdD2E http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 V1lE5k http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) 3w8sjw http://blog.numino.net/ 6.动画: ll9W98 http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) cq9Ur5 http://blog.numino.net/ $("#go").click(function(){ KDC4d7 http://blog.numino.net/ $("#block").animate({ xQIfd6 http://blog.numino.net/ width: "90%", vb4rMe http://blog.numino.net/ height: "100%", qNBaA1 http://blog.numino.net/ fontSize: "10em" 8gPR4y http://blog.numino.net/ }, 1000 ); 53kFNx http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 b5x7mc http://blog.numino.net/ 7.扩展: F8qGl4 http://blog.numino.net/ $.fn.background = function(bg){ FmQGSb http://blog.numino.net/ return this.css('background', bg); O59WJX http://blog.numino.net/ }; HTz20l http://blog.numino.net/ $(#element).background("red"); xv085g http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) 9bXboz http://blog.numino.net/
|
|