jQuery入门简介 |
1.精准简单的选择对象(dom): HNlKlS http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") rVQV04 http://blog.numino.net/ $('.element');//Class O60mNx http://blog.numino.net/ $('p');//html标签 ERqzQ5 http://blog.numino.net/ $("form > input");//子对象 9kRb05 http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 rytKwX http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 0TL2K6 http://blog.numino.net/ $(":input");//表单对象 9YPkY4 http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 1bKxCg http://blog.numino.net/ 2.对象函数的应用简单和不限制: KZ18xM http://blog.numino.net/ element.function(par); R0r6ua http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... PAgVjP http://blog.numino.net/ 3.对已选择对象的操作(包括样式): 6gI61H http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 9DpjG5 http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 BG237h http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 Hm0BED http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 ryVY9n http://blog.numino.net/ $("p").add("span");//给对象增加标签 Jxb6hk http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 8ru10S http://blog.numino.net/ $("p").parent();//对象的父级元素 QUevjh http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 nLBaox http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp I18mo8 http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 uG9s8i http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 JA6fV8 http://blog.numino.net/ 5.对事件的支持: VfTJFv http://blog.numino.net/ $("p").hover(function () { 247mY4 http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 eCMJA4 http://blog.numino.net/ }, function () { 01PiDV http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 0At1pn http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) 82Xv4L http://blog.numino.net/ 6.动画: CbVH1U http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) DYk122 http://blog.numino.net/ $("#go").click(function(){ 9rOYnr http://blog.numino.net/ $("#block").animate({ d8pPt4 http://blog.numino.net/ width: "90%", x43Us6 http://blog.numino.net/ height: "100%", xLv7hI http://blog.numino.net/ fontSize: "10em" C4bQcH http://blog.numino.net/ }, 1000 ); oM07Qb http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 1weWS5 http://blog.numino.net/ 7.扩展: w4vrCe http://blog.numino.net/ $.fn.background = function(bg){ zqUNEC http://blog.numino.net/ return this.css('background', bg); z90wj6 http://blog.numino.net/ }; Z0sZoe http://blog.numino.net/ $(#element).background("red"); q171Z1 http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) fR3dZa http://blog.numino.net/
|
|