1.选择器实例
语法 | 描述 |
---|---|
$(this) | 当前 HTML 元素 |
$("p") | 所有 <p> 元素 |
$("p.intro") | 所有 class="intro" 的 <p> 元素 |
$(".intro") | 所有 class="intro" 的元素 |
$("#intro") | id="intro" 的元素 |
$("ul li:first") | 每个 <ul> 的第一个 <li> 元素 |
$("[href$='.jpg']") | 所有带有以 ".jpg" 结尾的属性值的 href 属性 |
$("div#intro .head") | id="intro" 的 <div> 元素中的所有 class="head" 的元素 |
2.jQuery 事件
下面是 jQuery 中事件方法的一些例子:
Event 函数 | 绑定函数至 |
---|---|
$(document).ready(function) | 将函数绑定到文档的就绪事件(当文档完成加载时) |
$(selector).click(function) | 触发或将函数绑定到被选元素的点击事件 |
$(selector).dblclick(function) | 触发或将函数绑定到被选元素的双击事件 |
$(selector).focus(function) | 触发或将函数绑定到被选元素的获得焦点事件 |
$(selector).mouseover(function) | 触发或将函数绑定到被选元素的鼠标悬停事件 |
3.隐藏和显示
① $(selector).hide(speed,callback); ② $(selector).show(speed,callback);
可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。
可选的 callback 参数是隐藏或显示完成后所执行的函数名称。
下面的例子演示了带有 speed 参数的 hide() 方法:
实例
$("button").click(function(){
$("p").hide(1000);
});
③$(selector).toggle(speed,callback);
可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。
可选的 callback 参数是 toggle() 方法完成后所执行的函数名称。
4. 淡入淡出
通过 jQuery,您可以实现元素的淡入淡出效果。
jQuery 拥有下面四种 fade 方法:
- fadeIn() 用于淡入已隐藏的元素
- fadeOut() 方法用于淡出可见元素
- fadeToggle() jQuery fadeToggle() 方法可以在 fadeIn() 与 fadeOut() 方法之间进行切换。 如果元素已淡出,则 fadeToggle() 会向元素添加淡入效果。 如果元素已淡入,则 fadeToggle() 会向元素添加淡出效果
- fadeTo() 方法允许渐变为给定的不透明度(值介于 0 与 1 之间)。
5.滑动
jQuery 拥有以下滑动方法:
- slideDown() 方法用于向下滑动元素
- slideUp() 方法用于向上滑动元素
- slideToggle() jQuery slideToggle() 方法可以在 slideDown() 与 slideUp() 方法之间进行切换。 如果元素向下滑动,则 slideToggle() 可向上滑动它们。 如果元素向上滑动,则 slideToggle() 可向下滑动它们
实例
$("#flip").click(function(){
$("#panel").slideToggle();
}); 6.动画 jQuery animate() 方法用于创建自定义动画。
实例1
$("button").click(function(){
$("div").animate({
left:'250px',
opacity:'0.5',
height:'150px',
width:'150px'
});
});
实例2
隐藏,如果您希望在彼此之后执行不同的动画,那么我们要利用队列功能:
$("button").click(function(){
var div=$("div");
div.animate({height:'300px',opacity:'0.4'},"slow");
div.animate({width:'300px',opacity:'0.8'},"slow");
div.animate({height:'100px',opacity:'0.4'},"slow");
div.animate({width:'100px',opacity:'0.8'},"slow");
}); 7.停止
jQuery stop() 方法
jQuery stop() 方法用于停止动画或效果,在它们完成之前。
stop() 方法适用于所有 jQuery 效果函数,包括滑动、淡入淡出和自定义动画。
实例:
$("#stop").click(function(){
$("#panel").stop();
}); 8.回调 jQuery Callback 函数
$(selector).hide(speed,callback)
callback 参数是一个在 hide 操作完成后被执行的函数。
实例:
$("p").hide(1000,function(){
alert("The paragraph is now hidden");
}); 9.Chaining
Chaining 允许我们在一条语句中允许多个 jQuery 方法(在相同的元素上)。
实例:
下面的例子把 css(), slideUp(), and slideDown() 链接在一起。"p1" 元素首先会变为红色,然后向上滑动,然后向下滑动:
$("#p1").css("color","red").slideUp(2000).slideDown(2000); 10.获得内容和属性
三个简单实用的用于 DOM 操作的 jQuery 方法:
内容:
- text() - 设置或返回所选元素的文本内容
- html() - 设置或返回所选元素的内容(包括 HTML 标记)
- val() - 设置或返回表单字段的值
属性:
- attr() 方法用于获取属性值
11:添加元素
添加新的 HTML 内容
我们将学习用于添加新内容的四个 jQuery 方法:
- append() - 在被选元素的结尾插入内容
- prepend() - 在被选元素的开头插入内容
- after() - 在被选元素之后插入内容
- before() - 在被选元素之前插入内容
实例:
function appendText()
{
var txt1="<p>Text.</p>"; // 以 HTML 创建新元素
var txt2=$("<p></p>").text("Text."); // 以 jQuery 创建新元素
var txt3=document.createElement("p"); // 以 DOM 创建新元素
txt3.innerHTML="Text.";
$("p").append(txt1,txt2,txt3); // 追加新元素
}
12. 删除元素/内容
如需删除元素和内容,一般可使用以下两个 jQuery 方法:
- remove() - 删除被选元素(及其子元素)
- empty() - 从被选元素中删除子元素
实例:
$("#div1").remove();
$("#div1").empty();
下面的例子删除 class="italic" 的所有 <p> 元素:
$("p").remove(".italic"); 13. 获取并设置 CSS 类
jQuery 拥有若干进行 CSS 操作的方法。我们将学习下面这些:
- addClass() - 向被选元素添加一个或多个类
- removeClass() - 从被选元素删除一个或多个类
- toggleClass() - 对被选元素进行添加/删除类的切换操作
- css() - 设置或返回样式属性
实例
$("button").click(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
下面的例子将返回首个匹配元素的 background-color 值:
$("p").css("background-color");
下面的例子将为所有匹配元素设置 background-color 和 font-size:
$("p").css({"background-color":"yellow","font-size":"200%"}); 14.尺寸
jQuery 提供多个处理尺寸的重要方法:
- width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)
- height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)
- innerWidth() 方法返回元素的宽度(包括内边距)
- innerHeight() 方法返回元素的高度(包括内边距)
- outerWidth() 方法返回元素的宽度(包括内边距和边框)
- outerHeight() 方法返回元素的高度(包括内边距和边框)
实例:
$("button").click(function(){
var txt="";
txt+="Width: " + $("#div1").width() + "</br>";
txt+="Height: " + $("#div1").height();
$("#div1").html(txt);
});
显示文档和窗口的尺寸
$(document).ready(function(){
$("button").click(function(){
var txt="";
txt+="Document width/height: " + $(document).width();
txt+="x" + $(document).height() + "\n";
txt+="Window width/height: " + $(window).width();
txt+="x" + $(window).height();
alert(txt);
});
});
15 遍历
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhEAAAGhCAIAAABQ3nGtAAAgAElEQVR4nO3dO47ryt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ISpIoSplzPJMk2MIhrc9nlaNc8D//V/vi4zYr+TKobj6OmFm++aQr6Q8tL5z02JOvpby+PR4nGvYXvnBMppGBSNJa2Zw3J2XswsEx90Ow9efUTE4G+u7VuHx8lXoDKyzBkjoMd+YagIW+k0Ts3FFZ5OdnSD0kvBs7WJyhq9MZ+WJyZ+B2wedR+RT5GGTr+IrmTHmqGvpF3yWeHzVxpYJEgZL04SEcc9SJqrtucZUqK38eAlP+bZjobDzge90zZwXjttlonKGfi1vVWrO0CSJ2FAUkyY4LTTz1flUxi0vuDgTrhVce9nj0ayN6etnHLCwdfoijB33idH6Ts+7/ybkjK74eAlPCWOhSRVTcoZz/mhyhnPWaeJ5wrThavD4naj/dw1/Bp7pn/s5xy849uMyxug663FOi/EpGWPOeC3nJexKssfjvEpCGd+JzseaZ8fHNeM+PVqjBt+PsfXIAcdea9bx6tRrcFy/3TSjsBCYc1bYZzkL+477YrYL262w65Gf2qQnaioAYCJyBgBAi5wBANAiZwAAtMgZAAAtcgYAQIucAQDQImcAALTIGQAALXIGAECLnAEA0CJnAAC0yBkAAC1yBgBAi5wBANAiZwAAtMgZAACt/w/7UPpRuyo13wAAAABJRU5ErkJggg==" alt="" width="540" height="417" />
①祖先
向上遍历 DOM 树
这些 jQuery 方法很有用,它们用于向上遍历 DOM 树:
- parent() 方法返回被选元素的直接父元素。
- parents() 方法返回被选元素的所有祖先元素,它一路向上直到文档的根元素 (<html>)
- parentsUntil() 方法返回介于两个给定元素之间的所有祖先元素
实例:
$("span").parent().css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAisAAAGHCAIAAAD++oV3AAAPPElEQVR4nO3d4W7bOhKA0b7/6/WBZv/cbV1JZkiJ0pDUORAWjSLTTAzMB9m52F8BABl+ZW8AgJdSIAByKBAAORQIgBwKBEAOBQIghwIBkEOBAMhxUKDfALyYAgGQI79Aj+0AgEEoEAA5FAiAHAoEQA4FAiCHAgGQQ4G+2u/q2z5P7//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jh7FQhgCC+cvQoEMIQXzl4FAhjCC2evAgEM4YWzV4EAhvDC2atAAEN44exVIIAhvHD2KhDAEF44exUIYAgvnL0KBDCEF87e+Qr0+1+fFx8+anPx/nqpA0Yw+Oy9w2QF2pzcR2VzTc31+8sAnjfy7L3J3AX6dn7/5f42qGZZgMeMPHtvMlmB4ignUSzK4b8VCBjN4LP3DvMVaHPZ5h8XzwNkmWj29jJZgWqKUvk5UGFZgOeNPHtvMl+Bvr0Ltz95+JD9ld8eCPCkkWfvTSYrUOH6K08HkG7G2XvRCgVyEwMsYLrZe90KBQJYwAtnrwIBDOGFs1eBAIbwwtmrQABDeOHsVSCAIbxw9ioQwBBeOHuHLhDA24wwey/toYUCAQxkhNl7aQ8tBi0QAM0UKEKBADIoUIQCAWRQoAgFAsigQBEKBJBBgSIUCCCDAkUoEEAGBYpQIIAMChShQAAZFChCgQAyKFCEAgFkUKAIBQLIoEARCgSQQYEiFAgggwJFKBBABgWKUCCADAoUoUAAGRQoQoEAMihQhAIBZFCgCAUCyKBAEf//LTgcDofj+eMCBXI4HA7HheOCJQoEwIQUCIAcCgRADgUCIIcCAZBDgQDIoUAA5FAgAHIoEAA5FAiAHAoEQA4FAiCHAgGQQ4EAyKFAAOR4eP7/D8LUkIdEQ9M+AAAAAElFTkSuQmCC" alt="" width="428" height="240" />
$("span").parents().css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnsAAAE7CAIAAAAq5tAxAAAOL0lEQVR4nO3dUa7jNhJAUe1/X72CWZDnI0DHkWSSski6WDoHRJDWk2m5464b2cjM9gIABvvz58/262sAgPwUFwBm+PPnz/YHAOjqY3Ff22ZZlmVZVpeluJZlWZY1YzUUFwC4Q3EBYAbFBYAZFBcAZlBcAJhBcQFgBsUFgBkUFwBmuFvcX/+nxJZlWZYVaymuZVmWZc1YY4sLADy9uMfLK19w+/lfv/D3Bwb/3QOg3bOKe3oxVwvXfv7uzJYPFhqLHup3FYAWDy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UFwBmUFwAmEFxAWCGGcW1LMuyLOufpbiWZVmWNWONKi4A0EJxAWAGxQWAGRQXAGZQXACYQXEBYAbFBYAZFBcAZmgtrmVZlmVZt5fiWpZlWdaMVSwuANCJ4gLADIoLADMoLgDMoLgAMIPiAsAMigsAMyguAMyguAAwg+ICwAyKCwAzKC4AzKC4ADCD4gLADIoLADMoLgDMoLgAMIPiAsAMigsAMyguAMyguAAww6fi/h9aJ8RvbUZbuAAAAABJRU5ErkJggg==" alt="" width="550" height="196" />
$("span").parents("ul").css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlUAAAEhCAIAAADZP8KvAAAMJklEQVR4nO3dUY7bOhJA0ex/X28FWVDmr9EjyVSJRZss8xwYD4lMU3JPoy7kTjJ//vvvv38AsJk/+gfAhvQPgB3pHwA70j8AdqR/AOxI/wDYkf4BsCP9A2BHVfv358+f2yN969v7BE/RvQkAn1Gjf5c5edqb+PrDyoPgFd5eMwATFejfoRnnILX79HT9v2YpH1VNAgGW1epf43YntHXu5T+btI/c9im+/rKLT/ePPCuBANPd3P8lJ/X7+nfu0+F49/rLZa+up/EGX+3QfhUAn7F0/9o3T78DFolNcP3hYOTz0vZ5g+sB+KSS/Xv087yn6/+d+hd5R/oHUEuof7ddaT91WNa+kTqf/cPOVxu8pEY124sB+Lz7/l2WoFGFy1/HKxJZ9uhm7tH6n2Af/hu5cv0DKOTZ55+3PYt0MT76Gz17x/HDFR5uXiO3rZfJfHRJAHyG/t0cf3rnmry1BeAzPt2/p3P/cv37Pv98ddnt6zk868NPgPW98ed/58Dcfn54eQHBg286Hu9f41XB8wLwMW/885/nF/bN/cv9gyvzx4P9y18kAJ/00X//s3v0X95Hvvvzz8arDoFsn7fxRgCY5RP9a8emb8Mpx8/LIivHvncAhijw//8AAMPpHwA70j8AdqR/AOxI/wDYkf4BsCP9A2BH+gfAjvQPgB3pHwA70j8AdqR/AOxI/wDYkf4BsCP9A2BH+gfAjob17y8A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38ApBSd//oHQErR+a9/AKQUnf/6B0BK0fmvfwCkFJ3/g/sHwJ6GpOST9A+AAYak5JOG9Q8ACtE/AHakfwDsSP8A2JH+AbAj/QNgR/oHwI70D4Ad6R8AO9I/AHakfwDsSP8A2JH+AbAj/QNgR/oHwI70D4Ad6R8AO9I/AHakfwDsSP8A2JH+AbAj/QNgR/oHwI70D4Ad6R8AO9I/AHakfwDsSP8A2JH+AbAj/QNgR/8DyaL8lRrvZsoAAAAASUVORK5CYII=" alt="" width="452" height="184" />
$("span").parentsUntil("div").css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkwAAAEeCAIAAAD3qN31AAAMjUlEQVR4nO3dYXKjzBWGUe9/e1mQ8yuOBlDrbSTUfZtzivpqBiE1NlP3KSQ7+fkFgEX9jD4BALiKyAGwLJEDYFkiB8CyRA6AZc0euZ+f7Rnu95w7vv064RKnXwSAL5hrRh82ozcq+fGbIzfCM3x5zgCMMtEs3oRhX512hHqP/23msCtdOgcwp5/f/+Xh/Eu89/S/F2nveRmh/PjD+PW+fvKozgGMdTziu1/lssjtI7TZf/r4w8OenU/jC3z2Cu1nAfAFU0SufRv0WKmkKOHxm53J25vtdcPjAfiaqSPX9Rlb7/G/u8glX5HIARSyvftpx6P90Oaw9i3R5nXe/DJO2J9teEqNNLYPBuDL/gnS35///3Dzxzf2f85TkRzWdVvWdfxflTf/Tc5c5ACqeBGn3v2NY1on0fn72m/u35zh5jY0uQE97GLXKQHwBXeM3OH+3nvQN29SAfiCqyLXO9wPj7/u7cpnp90+n82j3qsEmNwHPpPbV+Tl230H5/Hqpx+v3p9HrvGscF0AvuMDP125f+K54X74+uGR7+8PI/f+SQLwNZcM4tPz/fCO8Oq3KxvP2lSwvW7jCwFgiE/O4nZRzr3gkP37w5IjP/u1A/A+QxmAZYkcAMsSOQCWJXIALEvkAFiWyAGwLJEDYFkiB8CyRA6AZYkcAMsSOQCWJXIALEvkAFiWyAGwLJEDYFk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IARCrOf5EDIFJx/oscAJGK81/kAIhUnP8iB0Ck4vwXOQAiFee/yAEQqTj/RQ6ASMX5L3IARCrOf5EDIFJx/oscAJGK81/kAIhUnP8iB0Ck4vwXOQAiFee/yAEQqTj/RQ6ASMX5L3IARCrOf5EDIFJx/p+MHAD3dEWKriNyAHS4IkXX6Y4cAFQhcgAsS+QAWJbIAbAskQNgWSIHwLJEDoBliRwAyxI5AJYlcgAsS+QAWJbIAbAskQNgWSIHwLJEDoBliRwAyxI5AJYlcgAsS+QAWJbIAbAskQNgWSIHwLJEDoBliRwAyxI5AJYlcgAsS+QAWJbIAbAskQNgWSIHwLL+C28+as1B9i/RAAAAAElFTkSuQmCC" alt="" width="380" height="139" />
②子孙
向下遍历 DOM 树
下面是两个用于向下遍历 DOM 树的 jQuery 方法:
- children() 方法返回被选元素的所有直接子元素。
- find() 方法返回被选元素的后代元素,一路向下直到最后一个后代
实例 :
$("div").children().css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfgAAAEJCAIAAAD3hKKUAAAIBElEQVR4nO3cUXKjOABF0ex/X7OCWZDnZypxQAgJHJAe55SqK8ZCkJ9rjJ3++geAaF8vAKIJPUA4oQcIJ/QA4YQeIJzQA4QTeoBwQg8QTugBwo0V+q+v/fPZmtOyb6+/WBPgYjeE7L2ei5LWH9a3b22sOzPfywAwhatTVWzr1rPtof+j5u4uq/XA+MqXtFsPzx5sL9z16Lc7eZJdy2o9MLideyB3hX6QeracxiCnCrCl9Wb3B470iWjWL7HXL1Ht7wB65/f+agB3uTP0J5P61fM+oLhj7wmfnwlwvfIl8GLLrx0a5pSP1F/DG0O//q27zhNgHE2fgi73OfQtw0+FvviCtHuI9tC3vLHYPU+Acfx/e/rXpoaOt7R1a5eOk7v11s2r+bNooQdGdnPoi5fPlUvpY6E/8BZkffTGVxGA0ZwKfW/gzs8/duum/RfsfeE58EsBXKzQysYr2Y/ciumdX78D0xjiw5fqQg/MqPC3UYsf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eE3jAMw7h+CL1hGEb4uCj0AMxG6AHCCT1AOKEHCCf0AOGEHiCc0AOEE3qAcEIPEE7oAcIJPUA4oQcIJ/QA4YQeIJzQA4QTeoBwQg8QTugBwgk9QDihBwj3H2BnVnqsK47fAAAAAElFTkSuQmCC" alt="" width="355" height="158" />
$("div").find("span").css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgUAAAEOCAIAAACW0fMEAAAI80lEQVR4nO3d4Y6juBKA0bz/680D1f1h3SgLlLEDHTA+R9aqO01cJCvxTSeZ3VcAQMTr6hMA4Bb0AIAIPQCguLIHr5ca/ZQnHKi47ALh2nQJTzuQSa8Or9fr89qx+Pbo1DmuSq//u/pE/uNu5wPcRO3SoAenuNuDvdv5ADfR2oMzRw5yPTrrPK96vJW5o/wrAH5JD1J6AExl47rw+rC4ZfOwyjHbI5NjNjdc/HRxWMvX9Qe1e3DjpbNy/OYOlSd5c6tzz7/xQQFTqV28XqsAVA7ePGB75N4V6vOSVzlm87DN27N91pfRLx7O7h3bn7fsi9PPXw+AtY4LWf06/vXVs3Lfeg8aN4+tP3rv7l8Z0b5/ts/u+ax7cO756wGwNksPevev3Kt9/+ynu+dT//0g20cPgCPO6UHv9aXxyqUHf9EDMQA2pZeqltc96rfXplYvkZu/cyzO50gPjr/e0rh/ts/u+dR7cPD89QDYlL7avv5i8eL15/HfDM5fVc9ufG1ZH5md5OJH9W8XT0XLw+k6pfr5fH5x7vk3PhxgQldeHVybfswTDlS4QAAQoQcAFHoAQIQeAFDoAQARegBAoQcAROgBAIUeABChBwAUegBAhB4AUOgBABF6AEChBwBE6AEAhR4AEPF1D/4BcJFzM/CmBwCDOTcDb4d6cO6pAFCnBwBE6AEAhR4AEKEHABR6AECEHgBQTNSD9569n8AVJ2AGs/SgfcPNIyUBeLwpenAwBr2bAIxID1oP0wPg2Z7fg5atGidKAvBgetB6TPthACMapgfvG3vPeP1hoXb1rQCeZJgeLG4/5S3irmO6hgI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MACj0AIEIPACj0AIAIPQCg0AMAIvQAgEIPAIjQAwAKPQAgIuJ/IuZC84M1f5QAAAAASUVORK5CYII=" alt="" width="401" height="173" />
③同胞
在 DOM 树中水平遍历
有许多有用的方法让我们在 DOM 树进行水平遍历:
- siblings() 方法返回被选元素的所有同胞元素
- next() 方法返回被选元素的下一个同胞元素
- nextAll() 方法返回被选元素的所有跟随的同胞元素
- nextUntil() 方法返回介于两个给定参数之间的所有跟随的同胞元素。
- prev() 工作方式与上面的方法类似,只不过方向相反
- prevAll()
- prevUntil()
实例:
$("h2").siblings().css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlMAAAE7CAIAAAB2bJMVAAAH7klEQVR4nO3dMVbiUBiGYfbjetyP63E7TDWlnZ2lHVOgGUggBC4a7v89z/kKJ0aG7j2JUTc7AEiyWfsNAMCvUj4AsigfAFmUD4AsygdAFuUDIIvyAZBF+QDIonwAZFE+ALIoHwBZlA+ALBfKtwWAzikfAFluKd/8OQDwmJQPgCzKB0AW5QMgi/IBkEX5AMhSrXyHb+xh3yQAK+q4fNP3sOTIuYMAhOi1fAsjd+746u8fgLX8VPlG59w3lsuzN/NZ8QPI9IPXfL9WvplXHj51bSwBqOqXyndHSzq38D2IH0Ag5QMgy/3Ltz0wOnLytJlzzr3+ws8u+Wbkxf8OgGLuXL6Z8Fy8IFvYIeUDoMU9yzdfsvkvWR6hhT1b8X4sAI+sYPmWv5ryAQR6iPJdW6AlNzzd6gTgpJ/6Pt/JR1rmv2S5+edrFr6y8gFkunP5Dj87+uDc05u3FWjJRefMi8seQKz7l+/XjC7vZiJ320OkAJTUcfn2Fr6Zh3rPAKyo+/IBwFWUD4AsygdAFuUDIIvyAZBF+QDIonwAZFE+ALIoHwBZlA+ALMoHQBblAyCL8gGQRfkAyKJ8AGRRPgCyrFS+zcbMzOz2NVA+MzPrcA1WLR8AXEv5AMiifABkUT4AsigfAFmUD4AsygdAFuUDIIvyAZBF+QDI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v0Ojgj5cPANaifABkUT4AsigfAFmUD4AsygdAFuUDIIvyAZBF+QDIonwAZFE+ALIoHwBZlA+ALMoHQBblAyDLSuXbbMzMzG5fA+UzM7MO12DV8gHAtZQPgCzKB0AW5QMgi/IBkEX5AMiifABkUT4AshQs38vT7uml6cUBKKxU+f68fB2/UL4/u6fDn+R/2v1pei8A9KRU+Xbf8Zsr3+tR7V6fv17qtentANCNuPLtU3d4wvNmt9nsnqUPIENo+TbP/4/sy/fijidAhrjyjbw8XXc+AL0rWr6n479G8Tw57/X/Z93nBIhSs3yHtZv/Nt7XzU+PdwLEKFq+g4u8fdtmLuzc8ASIonzfX+KyDyBDXPn2V3iHJygfQJS48j1PnnmZ/pwDAIXFlW90hTc8EeMBT4AQpcr3/8HO7/gNv5zs8BmWo9Pc5wQIU6p8AHCR8gGQRfkAyKJ8AGRRPgCyKB8AWZQPgCzKB0AW5QMgi/IBkKXv8pmZmd22BspnZmYdrsFK5QOAlSgfAFmUD4AsygdAFuUDIIvyAZBF+QDIonwAZFE+ALIoHwBZlA+ALMoHQBblAyCL8gGQRfkAyOLv85mZWYdroHxmZtbhGqxaPgC4lvIBkEX5AMiifABkUT4AsigfAFmUD4AsygdAFuUDIIvyAZBF+QDIonwAZFE+ALKUKt9wUBcBOKdU+UbHxQ+AqYLlm/knACgfAFmUD4AslcsnewBMFSzfMACYKlg+AJhRqnyu9gC4qFT5AOAi5QMgi/IBkEX5AMiifABkUT4AsvRdPjMzs9vWQPnMzKzDNVipfACwEuUDIIvyAZBF+QDIonwAZFE+ALIoHwBZlA+ALMoHQBblAyCL8gGQRfkAyKJ8AGRRPgCyKB8AWZQPgCzKB0AW5QMgi/IBkEX5AMhye/kAoF/KB0CW68oHAMUoHwBZlA+ALMoHQBblAyCL8gGQRfkAyPIPaFXm7ATNGtAAAAAASUVORK5CYII=" alt="" width="449" height="157" />
$("h2").nextAll().css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA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L3/zHOr/Id/u+x44dWTpa5vQkQpk72AOAq2QMgiOwBEET2AAgiewAEkT0AgsgeAEFkD4AgsgdAENkDIEjH2TPGGGPumwayZ4wxprdpsEb2AGAlsgdAENkDIIjsARBE9gAIInsABJE9AILIHgBBZA+AILIHQBDZAyCI7AEQRPYACCJ7AASRPQCC+Ht7xhhjepsGsmeMMaa3abBe9gDgVrIHQBDZAyCI7AEQRPYACCJ7AASRPQCCyB4AQWQPgCCyB0AQ2QMgiOwBEET2AAhSJ3uHk6IIwCV1sjc6r3wATFXL3syPACB7AASRPQCClM2e5gEwVS17hwGAqWrZA4AZdbJnnwfAVXWyBwBXyR4AQWQPgCCyB0AQ2QMgiOwBEKTj7BljjDH3TQPZM8YY09s0WCN7ALAS2QMgiOwBEET2AAgiewAEkT0AgsgeAEFkD4AgsgdAENkDIIjsARBE9gAIInsABJE9AILIHgBBZA+AILIHQBDZAyCI7AEQRPYACHJn9gCgX7IHQJAbsgcANcgeAEFkD4AgsgdAENkDIIjsARBE9gAI8g/6HUb/ZlMmzAAAAABJRU5ErkJggg==" alt="" width="496" height="178" />
$("h2").nextUntil("h6").css({"color":"red","border":"2px solid red"});
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAj0AAAGWCAIAAAAcwKXmAAAKMElEQVR4nO3dPVLj2hpAUebDWG7IfHo8PY83AndESEZG8qrIfAOD2viv1Ve28T5eq74AyUI423WOBTysAaDj4bvfAAD8Bd0CoES3ACjRLQBKdAuAEt0CoES3ACjRLQBKdAuAEt0CoES3ACjRLQBKdAuAEt0CoORwt1YAcEt0C4CSWd1asIwDgPPQLQBKdAuAEt0CoES3ACjRLQBK8t3afmM3+yYBOJdSt/bfw5wzx04CUJTp1sxEHTv/7e8fgLM4W7d2rjlv6uZH68Sr0gUwgHOut67WrRN3nl7629QBkHCpbp3RnErNfA/SBVCnWwCUnKFbqy07Zw5eduKaY/ef+eqcD+H++OMAuGVLu3UiG39cDM2siG4BMFnUrdMdOv0t8xMys0b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AuAEt0CoCTWLWOMMeZBt4wxxrRmgWt1CwDOQbcAKNEtAEp0C4AS3QKgRLcAKNEtAEp0C4AS3QKgRLcAKNEtAEp0C4AS3QKgRLcAKNEtAEr8/y1jjDFXnwV0yxhjzNVnget2C4A7p1sAlOgWACW6BUCJbgFQolsAlOgWACW6BUBJu1ubk//8c/T6M/2SGgC3ot2tzfkT3QJgMLoFQMkg3drfDLRJCDCkEbo1vbR9zbGvAUgboVvTPuHptgEwgGG7Zb0FMCTdAqCk3a2dJy92nsLwXAbAeNrdAuDe6BYAJboFQIluAVCiWwCU6BYAJboFQIluAVAS65YxxhjzoFvGGGNas8C1ugUA56BbAJToFgAlugVAiW4BUKJbAJToFgAlugVAiW4BUKJbAJToFgAlugVAiW4BUKJbAJToFgAlV+rWCgA+LQ/KdKhbAFzc8qBMh5ft1pI7ADAA3QKgRLcAKNEtAEp0C4AS3QKgRLcAKNEtAEri3Xp7Wa1Wq5e3vcs3L2w8v74v+ckA3JB4t9bvr8/73Xp/fVYrgDEN0a0tL29HWgbAEMbo1vPr+9Yqa3uP0D4hwFiG6NZmbbXTrY8F19uLcgEMZMRubVq13S2bhgCjiHfrc0vw5W36oOt3ubY/8wJgDPFuAXBndAuAEt0CoES3ACjRLQBKdAuAEt0CoES3ACiJdQsAVroFQMvyoEyHl+oWAJyFbgFQolsAlOgWACW6BUCJbgFQolsAlOgWACW6BUCJbgFQolsAlOgWACW6BUCJbgFQolsAlFypWysA+LQ8KNOhbgFwccuDMh1etltL7gDAAHQLgBLdAqBEtwAo0S0ASnQLgBLdAqBEtwAo0S0ASs7frf8BQMfD/wGgQ7cAKNEtAEp0C4AS3QKg5F/KPDAub5AkKQAAAABJRU5ErkJggg==" alt="" width="454" height="224" />
④过滤
first() 方法返回被选元素的首个元素。
last() 方法返回被选元素的最后一个元素
eq() 方法返回被选元素中带有指定索引号的元素。 索引号从 0 开始,因此首个元素的索引号是 0 而不是 1
filter() 方法允许您规定一个标准。不匹配这个标准的元素会被从集合中删除,匹配的元素会被返回
not() 方法返回不匹配标准的所有元素。
实例:
$("p").eq(1);
$("div p").first().css("background-color","yellow");
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARsAAACsCAIAAADE958PAAAM+0lEQVR4nO2d23njIBBG1Y/rcT+uJ/WkH+9DEluCucIgO9lzPh7WMpeBmR8QUrzbHQDq2F5tAMCfAkUBVIKiACpBUQCVoCiASlAUQCUoCqASFAVQCYoCqARFAVSCogAqQVEAlaAogEpQFEAlKAqgEhQFUAmKAqgERQFUklPUx3XbtuvHIluWtvF5u2zbtm3b5fZZXXeGj2uBDR/Xop74FX2NW40/Pm+X1dETp7Jje1KKekRl2ptfnnPNH28gasIX69z63QPd+p0ZGSuOE8K+LzOd2Y23Uo2fI8OP3S+e1aq7dSClqJmg/CmrljtEyYKeznmzs85FaefHl1EzhIavH4+A+BqjbJ195SGvlOjgWeGof/dqKKIy1HRFfRm+H0V//C2eA/Gosx0bx2Uf1xmnTs+P/Xa0H6LDN2JLkegXYuaR/eO6XW4fR0Udi8S981NIL/FweeGqsnB96FsINDAXVh0BAf8099m5MUk/PSkOEz0961xHUQOCC8zfmgqlAofV6OtrzSjRFbvysU5812K4c24O9RpepqnpSJ1BW6P6aJk3sz8c0LaC9h5LXRSKSMXjtm2X61W74+7vmlI7tJSiYvdon7fLz7ftIUl3aGLMMp+3S8WGYUnQ+0vvShRFCS5zboQi3eiOVzxFSVPw7ArpxMEu4txsT3O0AOsbLVGUNhiBWS8w9Xy3plcmbOCzfHfA3jBM7UaM+9ilUpMVZQjKZ2DfVKgodTi16BzxXjd9eIvJSYqKoBVtz1mDq359dAq7Xz+3tdTueHZqmark2ntPOnF3GP54cK5Zo+Q4lK+OGP5dk2b0vpbVijLWRW2cPEV9V2kNt70UFmzA9ztk/7hqjFUn+Js0qauCun7cxX3R6M511a5PuqEQgzC/n7fitZ8BT1eU/6QqpCjboWVnVGXPqNM3v+s2ftuzme68oD3lbmav9kp88ejO+urvo3pNCUOffI9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mGcz9mzxi0aG4BplyMAoaLQllkJRsJroLdCzQEZRjVwHdn19JUZ+V1F3dn2wmMN9vEZbxuORbV/kPqQoe4nL7voAVrMq5lI6FEsZYtZaiaxRAEsh5gAqQVEAlaAogEpQFEAlKAqgEhQFUAmKAqgERQFUgqIAKkFRAJWgKIBKUBRAJSgKoJJ/aXInRVd6/SAAAAAASUVORK5CYII=" alt="" />
$("p").filter(".intro").css("background-color","yellow"); //class='intro'
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATMAAADWCAIAAAAyxPKMAAAO/klEQVR4nO2dW3brIAxFmU/Hk/l0PB1P55P70TYl6IGEcaL07r304cQ8jQ7C2E3bFQDq0Z7dAABQQJkAFUGZABVBmQAVQZkAFUGZABVBmQAVQZkAFUGZABVBmQAVQZkAFUGZABVBmQAVQZkAFUGZABVBmQAV2aPMj0tr7fKxpawH1/H5/tZaa629vX/uLjvDx2VDGz4um3oyL+jruu0Zj8/3t7O9J87Ojh1hizJv3p32ii8PmF6G9QqiTfjivPH47oHd+q4ZmVbcTyx9X450prveRjHzFBl+2v3k2XF3tw6xRZlHnPsnr5nvzttOuGLHvEK0bopRz49PRJuhVHz5uDnW1zXKlikLD43KFj39Frg6vr2qNvFMceaV+XUB+tGYj+O8vLsRHq/xZOg/Lkec4/B8LZfZ8hLdnVFriqhI8b1b8o9Le3v/uFfmfZb46PxksnPchnxjlDs/XuUuxjG3OoyizOjc89PsT+EOSeR0aQy86jFHnWSizAXhBuKJpWYtw110/DptNUodii5/rBPfpTjDeWwunlV8mjYPe+ojycZM6XXHuys3Yawlrr92NIPUJlJ+3Vp7u1ysnQ15V5laeaaUGbuH/Xx/+zk7bkaJzSlntvp8f9uxgDlFPPOlQCWSylSGfnKjGLkcYjtspkwtJByN2BN/6jx3muy3OZajykq3KNO6GIHZMzCFfddmF6bcmGT57oC/gDm0OnLu80tJNqdMR5hzFtaDG5VpDovl5SteIKahWXB7kDIjWFnHffHgKmS/lyur+nlqL/R3/HaqjD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U5ErkJggg==" alt="" />
16. ajax
① load() 方法从服务器加载数据,并把返回的数据放入被选元素中
$(selector).load(URL,data,callback);
必需的 URL 参数规定您希望加载的 URL。
可选的 data 参数规定与请求一同发送的查询字符串键/值对集合。
可选的 callback 参数是 load() 方法完成后所执行的函数名称。
回调函数可以设置不同的参数:
- responseTxt - 包含调用成功时的结果内容
- statusTXT - 包含调用的状态
- xhr - 包含 XMLHttpRequest 对象
下面的例子会在 load() 方法完成后显示一个提示框。如果 load() 方法已成功,则显示“外部内容加载成功!”,而如果失败,则显示错误消息:
实例:
$("button").click(function(){
$("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){
if(statusTxt=="success")
alert("外部内容加载成功!");
if(statusTxt=="error")
alert("Error: "+xhr.status+": "+xhr.statusText);
});
});
②$.get() 方法通过 HTTP GET 请求从服务器上请求数据。
实例:http://www.w3school.com.cn/tiy/t.asp?f=jquery_ajax_get
$("button").click(function(){
$.get("demo_test.asp",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
③$.post() 方法通过 HTTP POST 请求从服务器上请求数据。
$.post(URL,data,callback);
必需的 URL 参数规定您希望请求的 URL。
可选的 data 参数规定连同请求发送的数据。
可选的 callback 参数是请求成功后所执行的函数名。
下面的例子使用 $.post() 连同请求一起发送数据:
实例
$("button").click(function(){
$.post("demo_test_post.asp",
{
name:"Donald Duck",
city:"Duckburg"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
}); 17 jQuery noConflict() 方法
其他一些 JavaScript 框架包括:MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 以及 Ext JS。
其中某些框架也使用 $ 符号作为简写(就像 jQuery),如果您在用的两种不同的框架正在使用相同的简写符号,有可能导致脚本停止运行。
jQuery 的团队考虑到了这个问题,并实现了 noConflict() 方法 noConflict() 方法会释放会 $ 标识符的控制
实例1:
您仍然可以通过全名替代简写的方式来使用 jQuery
$.noConflict();
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery("p").text("jQuery 仍在运行!");
});
});
实例2:
您也可以创建自己的简写。noConflict() 可返回对 jQuery 的引用,您可以把它存入变量,以供稍后使用。请看这个例子:
var jq = $.noConflict();
jq(document).ready(function(){
jq("button").click(function(){
jq("p").text("jQuery 仍在运行!");
});
});
实例3:
如果你的 jQuery 代码块使用 $ 简写,并且您不愿意改变这个快捷方式,那么您可以把 $ 符号作为变量传递给 ready 方法。这样就可以在函数内使用 $ 符号了 - 而在函数外,依旧不得不使用 "jQuery":
$.noConflict();
jQuery(document).ready(function($){
$("button").click(function(){
$("p").text("jQuery 仍在运行!");
});
});
参考文献:http://www.w3school.com.cn/jquery/jquery_selectors.asp 好好学习哟!