Javascript jquery$。每个未附加到字符串
我正在玩extend.js,我在jQuery的Javascript jquery$。每个未附加到字符串,javascript,jquery,Javascript,Jquery,我正在玩extend.js,我在jQuery的$上遇到了一些问题。每个都附加到一个字符串 var Test = Class.extend(function(){ this.dom = '<div '; this.class; this.id; this.add_class = function(){ this.dom += 'class = "'; $.each(this.class, function(i,e){
$上遇到了一些问题。每个都附加到一个字符串
var Test = Class.extend(function(){
this.dom = '<div ';
this.class;
this.id;
this.add_class = function(){
this.dom += 'class = "';
$.each(this.class, function(i,e){
console.log(e);
this.dom += e;
this.dom += ' ';
});
this.dom += '"';
return this;
};
this.add_id = function(){
this.dom += 'data-id = "'+this.id+'" ';
return this.dom;
};
});
var tester = new Test();
tester.class = ["coolClass", "TESTER"];
tester.id = "coolId";
console.log(tester.add_class().add_id());
var Test=Class.extend(函数(){
this.dom='将此
值重新分配给函数
块中的不同对象。请签出
你需要做一些类似的事情
var that = this;
$.each(this.class, function(i,e){
console.log(e);
that.dom += e;
that.dom += ' ';
});
上下文
在$.each回调中,this
是当前正在迭代的项。不是this
对象是Test
使用以下命令:
var oThis = this;
$.each(this.class, function(i,e){
console.log(e);
oThis.dom += e;
oThis.dom += ' ';
});
我知道我该睡觉了,谢谢。
var oThis = this;
$.each(this.class, function(i,e){
console.log(e);
oThis.dom += e;
oThis.dom += ' ';
});