[英]Event Listener not getting added to the div element
我有以下JavaScript代碼:
this._incrementButtonProperties = {
"enabled": this.properties.incrementButtonConfig.enabled,
"enabledClass" : "SchedMainCtrlIncrementBtn_En",
"disabledClass" : "SchedMainCtrlIncrementBtn_Ds",
"appData" : this.properties.incrementButtonConfig.appData,
"text" : this.properties.incrementButtonConfig.text,
"incrementSelectCallback" : this._incrementButtonSelectHandler.bind(this),
};
和
this._incrementBtn = document.createElement('div');
this._incrementBtn .className = this._incrementButtonProperties.enabledClass;
this.divElt.appendChild(this._incrementBtn);
和
this._incrementBtn.addEventListener('click', this._incrementButtonProperties.incrementSelectCallback, false);
也,
this._prototype._incrementButtonSelectHandler = function(ctrlRef, appData, params)
{
// + & -
alert("_incrementButtonSelectHandler called... ");
}
但是沒有添加事件偵聽器:-(如果我編寫document.addEventListener('click',this._incrementButtonProperties.incrementSelectCallback,false);-那么偵聽器將被添加,但是我只需要它用於“ this._incrementBtn” div元素。
知道發生了什么事嗎?
注意:請不要建議使用jQuery等。我不想使用任何框架。
謝謝
斯內哈
它真的應該閱讀this._prototype._incrementButtonSelectHandler = ...嗎?
不應該是this.prototype嗎? 否則,我看不到this._incrementButtonSelectHandler如何對應於this._prototype._incrementButtonSelectHandler。
此外,您在this._incrementButtonProperties {...}中使用逗號結尾,直到Ecmascript 5實際上無效為止,即使大多數瀏覽器都接受它也沒有任何抱怨。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.