jQuery入门简介 |
1.精准简单的选择对象(dom): dAIa33 http://blog.numino.net/ $('#element');// 相当于document.getElementById("element") DMek89 http://blog.numino.net/ $('.element');//Class VHPRJ2 http://blog.numino.net/ $('p');//html标签 RDxBcQ http://blog.numino.net/ $("form > input");//子对象 TsLmx1 http://blog.numino.net/ $("div,span,p.myClass");//同时选择多种对象 2xhh5r http://blog.numino.net/ $("tr:odd").css("background-color", "#bbbbff");//表格的隔行背景 9c6DgA http://blog.numino.net/ $(":input");//表单对象 6xglQL http://blog.numino.net/ $("input[name='newsletter']");//特定的表单对象 GLztk4 http://blog.numino.net/ 2.对象函数的应用简单和不限制: vwWM3c http://blog.numino.net/ element.function(par); mxQ7N3 http://blog.numino.net/ $(”p.surprise”).addClass(”ohmy”).show(”slow”)... iK776h http://blog.numino.net/ 3.对已选择对象的操作(包括样式): jVqUvp http://blog.numino.net/ $("#element").addClass("selected");//给对象添加样式 QHxll1 http://blog.numino.net/ $('#element').css({ "background-color":"yellow", "font-weight":"bolder" });//改变对象样式 21n1C0 http://blog.numino.net/ $("p").text("Some new text.");//改变对象文本 XoW8Un http://blog.numino.net/ $("img").attr({ src: "test.jpg", alt: "Test Image" });//改变对象文本 J3UMTs http://blog.numino.net/ $("p").add("span");//给对象增加标签 377qSC http://blog.numino.net/ $("p").find("span");//查找对象内部的对应元素 i8ChIq http://blog.numino.net/ $("p").parent();//对象的父级元素 nAoef0 http://blog.numino.net/ $("p").append("<b>Hello</b>");//给对象添加内容 7v7w8N http://blog.numino.net/ 4.支持aJax,支持文件格式:xml/html/script/json/jsonp 0xshSb http://blog.numino.net/ $("#feeds").load("feeds.html");//相应区域导入静态页内容 xq15OR http://blog.numino.net/ $("#feeds").load("feeds.php", {limit: 25}, function(){alert("The last 25 entries in the feed have been loaded");});//导入动态内容 BIy9PL http://blog.numino.net/ 5.对事件的支持: CyATYV http://blog.numino.net/ $("p").hover(function () { uyS0Dl http://blog.numino.net/ $(this).addClass("hilite");//鼠标放上去时 BvM571 http://blog.numino.net/ }, function () { UYDSJ3 http://blog.numino.net/ $(this).removeClass("hilite");//移开鼠标 7NOJSg http://blog.numino.net/ });//鼠标放上去和移开的不同效果(自动循环所有p对象) LVXC2c http://blog.numino.net/ 6.动画: ikxlUr http://blog.numino.net/ $("p").show("slow");//隐藏对象(慢速渐变) H6O37r http://blog.numino.net/ $("#go").click(function(){ B98wB7 http://blog.numino.net/ $("#block").animate({ 7kQO3h http://blog.numino.net/ width: "90%", hjI4oy http://blog.numino.net/ height: "100%", 430PQ3 http://blog.numino.net/ fontSize: "10em" Ih6MzW http://blog.numino.net/ }, 1000 ); 3inYl3 http://blog.numino.net/ });//鼠标点击后宽、高、字体的动态变化 SQx4kE http://blog.numino.net/ 7.扩展: h6wA3s http://blog.numino.net/ $.fn.background = function(bg){ 1UxfGh http://blog.numino.net/ return this.css('background', bg); 3z9gpI http://blog.numino.net/ }; cBuDY3 http://blog.numino.net/ $(#element).background("red"); aIC7z7 http://blog.numino.net/ 如果要为每一个jQuery 对象添加一个函数,必须把该函数指派给 $.fn,同时这个函数必须要返回一个 this(jQuery 对象) NuWMWb http://blog.numino.net/
|
|