jQuery入门简介 |
1.精准简单的选择对象(dom): jV70vt http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") NZ8Hm6 http://blog.numino.net/ $('.element');//Class dxzaoi http://blog.numino.net/ $('p');//html标签 8Jt4H2 http://blog.numino.net/ $("form > input");//子对象 5EcMDS http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 8E35nN http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 9MJ091 http://blog.numino.net/ $(":input");//表单对象 UuTO34 http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 hclMc9 http://blog.numino.net/ 2.对象函数的应用简单和不限制: bdzgg3 http://blog.numino.net/ element.function(par); Fjr9bR http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... xKl1EE http://blog.numino.net/ 3.对已选择对象的操作(包括样式): GwM2J4 http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 2JHXUz http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 B3bfcX http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 Q946rB http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 GIqH0u http://blog.numino.net/ $("p").add("span");//给对象增加标签 38jHj4 http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 Fy9Li9 http://blog.numino.net/ $("p").parent();//对象的父级元素 VP133u http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 VkqV51 http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp qbw5gh http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 cu4jZH http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 I383u5 http://blog.numino.net/ 5.对事件的支持: EK5f60 http://blog.numino.net/ $("p").hover(function () { NydVK7 http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 oKBLWb http://blog.numino.net/ }, function () { 3Ux0H2 http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 fN2ABf http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) D5We8i http://blog.numino.net/ 6.动画: iP0cV5 http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) Eepxob http://blog.numino.net/ $("#go").click(function(){ fiyrBh http://blog.numino.net/ $("#block").animate({ 1QDHpH http://blog.numino.net/ width: "90%", 1Y27n6 http://blog.numino.net/ height: "100%", 47A81V http://blog.numino.net/ fontSize: "10em" KJCZhW http://blog.numino.net/ }, 1000 ); UUOaV4 http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 9S8wcU http://blog.numino.net/ 7.扩展: KgADsP http://blog.numino.net/ $.fn.background = function(bg){ j2Vqnu http://blog.numino.net/ return this.css('background', bg); pPh5C2 http://blog.numino.net/ }; 65fi2D http://blog.numino.net/ $(#element).background("red"); FsgC2r http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) ybBc9V http://blog.numino.net/
|
|