jQuery in action 3rd - Operating on a jQuery collection
1、创建新 DOM 元素
$('<div>Hello</div>');
$('<img>', {
src: 'images/little.bear.png',
alt: 'Little Bear',
title: 'I woof in yor general direction',
click: function() {
alert($(this).attr('title'));
}
}).appendTo('body');
2、操作 jQuery collection 对象的方法
get([index])
示例:$('img[alt]').get(0)
eq(index)
示例:$('img[alt]').eq(2)
first()
示例:$('img[alt]').first()
last()
示例:$('img[alt]').last()
toArray()
示例:$('img[alt]').toArray()
index()
示例:$(#main-menu > li').index($('#blog-link'));
父子、祖先、子孙关系函数
add()
not()
示例,
$('div').not(function(index) {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return $(this).children().length > 2;
});
filter()
示例,
$('td').filter(function() {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.innerHTML.match(/^\d+$/);
});
$('img').filter('[title*="dog"]').addClass('red-border');
slice()
has()
map()
示例,
$('div').map(function() {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.id;
});
each()
示例,
$('img').each(function(index) {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.id;
});
is()
end()
addBack()
最新文章
- [PHP源码阅读]strtolower和strtoupper函数
- Excel VBA自定义函数编写(UDF, User-Defined Function)
- POJ 1984 Navigation Nightmare 带全并查集
- lua module package.seeall选项
- 配置eclipse集成开发环境_编译_调试
- C语言位操作(转)
- 实用的插件:跨浏览器复制jQuery-zclip
- Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题的解决
- find用法
- Scala中的元组
- [iOS]使用symbolicatecrash分析crash文件
- JQuery UI 封装了一些常用模板
- 梳理spring的层次结构的神器
- HTML&;javaSkcript&;CSS&;jQuery&;ajax(五)
- 前缀和的应用 CodeForces - 932B Recursive Queries
- 阿里八八Alpha阶段Scrum(6/12)
- 8.23 js
- php导出excel(xls或xlsx)(解决长数字显示问题)
- vue.js-列表分页
- C语言动态库和静态库的使用及实践