gpt4 book ai didi

javascript - javascript中 "click"事件的嵌套函数调用

转载 作者:行者123 更新时间:2023-11-30 21:05:50 25 4
gpt4 key购买 nike

<分区>

这是我的代码,现在有些人可能会说为什么不只在该功能 block 中包含一行代码,但我不想这样做,我该如何实现。如何在按钮的“点击”事件上调用 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);

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com