attr: function( name, value, type ) { var options = name; //给name参数添加一个引用 // Look for the case where we're accessing a style value if ( typeof name === "string" ) //判断name的类型是否是string类型,如果是则执行下一个if,如果不是就执行return this.each(function(i){ // }); if ( value === undefined ) 判断传递给函数的参数value是否定义,如果没定义则执行return语句,否则执行else语句 return this[0] && jQuery[ type || "attr" ]( this[0], name ); //函数递归且返回this[0] 相当于执行 attr: function(this[0],name){ // } else { options = {}; 将options定义为一个数组 options[ name ] = value; 数组的key为那么,值为value alert(options[name ]); } // Check to see if we're setting style values return this.each(function(i){ //遍历数组this // Set all the styles for ( name in options ) jQuery.attr(type ?this.style :this,name, jQuery.prop( this, options[ name ], type, i, name ));//三目运算符 }); },抱歉,没弄懂这段代码要做什么-------
var options = name; //给name参数添加一个引用
// Look for the case where we're accessing a style value
if ( typeof name === "string" ) //判断name的类型是否是string类型,如果是则执行下一个if,如果不是就执行return this.each(function(i){ // });
if ( value === undefined ) 判断传递给函数的参数value是否定义,如果没定义则执行return语句,否则执行else语句
return this[0] && jQuery[ type || "attr" ]( this[0], name ); //函数递归且返回this[0] 相当于执行 attr: function(this[0],name){ // }
else {
options = {}; 将options定义为一个数组
options[ name ] = value; 数组的key为那么,值为value
alert(options[name ]);
} // Check to see if we're setting style values
return this.each(function(i){ //遍历数组this
// Set all the styles
for ( name in options )
jQuery.attr(type ?this.style :this,name, jQuery.prop( this, options[ name ], type, i, name ));//三目运算符
});
},抱歉,没弄懂这段代码要做什么-------