【发布时间】:2017-10-07 17:40:23
【问题描述】:
这是我的代码,现在有些人可能会说为什么不在该功能块中包含一行代码,但我不想,我该如何实现。如何在按钮的“单击”事件上调用 this.click 方法
var i = 0;
function el() {
this.type = "button",
this.el = false,
this.click = function () {
this.setHtml(i++);
},
this.setHtml = function (t) {
this.el.innerHTML = t;
}
fragment = document.createDocumentFragment(),
element = fragment.appendChild(document.createElement(this.type));
element.setAttribute("data-el", this.type);
element.innerHTML = "Default Button";
this.el = element;
attachEvent("click", this);
}
// this should be a seperate function ....
function attachEvent(ev, me){
//me doesn't work, but i want it to call the click method
me.el.addEventListener("click", me.click, false);//....
}
div = new el();
document.getElementById('areaA').appendChild(div.el);
【问题讨论】:
标签: javascript function ecmascript-6