我正在尝试将我的元素的类设置在同一元素的数据对象中,但它仍然返回undefined.
$(this).data({
orgSize:{ // Write all the sizes as data. For future reference.
width: $(this).width(), //returns the width just fine!
height: $(this).height() //returns the height just fine!
},
orgClass: function(){
cl = $(this).attr('class');
if(cl){
return ' ' + cl;
}else{
return ' somethingelse';
}
} //returns undefined
});
console.log($(this).attr('class')) //returns the class
Run Code Online (Sandbox Code Playgroud)
编辑:问题在orgClass中.
var me = $(this);
me.data({
orgSize : { width:me.width(), height:me.height() },
orgClass : function(){
cl = me.attr('class');
return cl ? (' '+cl) : ' somethingelse';
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |