当我到达 console.log()
它的返回窗口时。
如何获取考虑中的元素?
let builder = function(){
this.box = $(`<div id="box" class="box">`);
this.inputcontainer = $(`<div id="inputcontainer" class="inputcontainer">`).appendTo(this.box);
this.textarea = $(`<textarea id="textarea"></textarea>`).appendTo(this.inputcontainer);
this.textarea.on("change keyup keydown input paste", this.postmsg);
this.chat.appendTo($('body'));
}
//someothercode
builder.prototype.postmsg = (e) => {
console.log(this); // returns window when I need it to be referencing textarea
}
let instance = new builder();
最佳答案
builder.prototype.postmsg = function(e){
console.log(this.textarea);
}
关于javascript - 在使用稍后提到的原型(prototype)的类中设置事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47495634/