jquery对象的基本方法和属性--学习笔记
2017-10-01 09:47
776 查看
toArray:专属组
toArray: function() {
return core_slice.call( this );
},$('div') : { 0 : div , 1 : div , 2 : div , length : 3 },得到的是json对象;
$('div').toArray() : [div,div,div],得到的是数组。原生数组,不能调用jQuery方法。
get:转原生集合
get: function( num ) {
return num == null ?
// 没有参数时,调用toArray方法
this.toArray() :
// 如果是负数,要加上数组长度
( num < 0 ? this[ this.length + num ] : this[ num ] );
},
$('div').get(-1).innerHTML = '222222222';将最后一个div的内容变为222222222
pushStack:jQuery对象的入栈
pushStack: function( elems ) {
// Build a new jQuery matched element set
var ret = jQuery.merge( this.constructor(), elems );
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;
// Return the newly-formed element set
return ret;
},
调用pushStack方法
slice: function() {
return this.pushStack( core_slice.apply( this, arguments ) );
},
first: function() {
return this.eq( 0 );
},
last: function() {
return this.eq( -1 );
},
eq: function( i ) {
var len = this.length,
j = +i + ( i < 0 ? len : 0 );
return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
},
map: function( callback ) {
return this.pushStack( jQuery.map(this, function( elem, i ) {
return callback.call( elem, i, elem );
}));
},
end: function() {
return this.prevObject || this.constructor(null);
},
$('div').eq(0).css('background','red');
toArray: function() {
return core_slice.call( this );
},$('div') : { 0 : div , 1 : div , 2 : div , length : 3 },得到的是json对象;
$('div').toArray() : [div,div,div],得到的是数组。原生数组,不能调用jQuery方法。
get:转原生集合
get: function( num ) {
return num == null ?
// 没有参数时,调用toArray方法
this.toArray() :
// 如果是负数,要加上数组长度
( num < 0 ? this[ this.length + num ] : this[ num ] );
},
$('div').get(-1).innerHTML = '222222222';将最后一个div的内容变为222222222
pushStack:jQuery对象的入栈
pushStack: function( elems ) {
// Build a new jQuery matched element set
var ret = jQuery.merge( this.constructor(), elems );
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;
// Return the newly-formed element set
return ret;
},
调用pushStack方法
slice: function() {
return this.pushStack( core_slice.apply( this, arguments ) );
},
first: function() {
return this.eq( 0 );
},
last: function() {
return this.eq( -1 );
},
eq: function( i ) {
var len = this.length,
j = +i + ( i < 0 ? len : 0 );
return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
},
map: function( callback ) {
return this.pushStack( jQuery.map(this, function( elem, i ) {
return callback.call( elem, i, elem );
}));
},
end: function() {
return this.prevObject || this.constructor(null);
},
<div>div</div> <div>div</div> <div>div</div> <div>div</div> <span>span</span>
$('div').pushStack( $('span') ).css('background','red').end().css('background','yellow');
$('div').slice(1,3).css('background','red').end().css('color','blue');
$('div').eq(0).css('background','red');
相关文章推荐
- Jquery学习笔记:获取jquery对象的基本方法
- 巴巴运动网学习笔记三之产品分类实体对象基本属性的JPA映射,用泛型技术对产品分类的业务管理Bean抽象,单元测试产品分类的业务管理Bean.,重载业务管理Bean的删除方法,
- jQuery源码学习之三 (jQUery对象的实例属性和方法)
- jQuery源码学习之三 (jQUery对象的实例属性和方法)
- JNI学习笔记:(1)开篇(2)本地代码访问Java代码 (3)本地方法取得Java属性/调用java方法 (4)本地代码创建Java对象(包括javaString) (5) 本地方法处理java数组
- JavaScript学习笔记8-jQuery表单对象属性过滤
- C++学习笔记->类、对象、属性、方法
- jQuery学习笔记之jQuery原型属性和方法
- jQuery源码研究分析学习笔记-静态方法和属性(10)
- jQuery源码学习 item2-jQuery对象及其属性和方法
- jquery学习笔记-jQuery操纵DOM元素属性 attr()和removeAtrr()方法
- JavaScript 对象属性操作和方法学习笔记(上)
- [原创]java WEB学习笔记59:Struts2学习之路---OGNL,值栈,读取对象栈中的对象的属性,读取 Context Map 里的对象的属性,调用字段和方法,数组,list,map
- scala 学习笔记(04) OOP(上)主从构造器/私有属性/伴生对象(单例静态类)/apply方法/嵌套类
- PHP 面向对象程序设计(oop)学习笔记 (二) - 静态变量的属性和方法及延迟绑定
- jQuery学习笔记(一) 取值、赋值的基本方法
- C++学习笔记5:从方法到属性(面向对象基础)
- 访问form对象的关键属性和方法【学习笔记】