该对象如下所示:
这就是我访问它的方式:console.log(this)
(this
输出Directive
对象)。
如何调用该对象的 ondrag
事件?
我尝试过这个:
this.el('ondrag', function(event) {
console.log(event)
})
但是我得到了:
caught TypeError: this.el is not a function
访问 ondrag
事件的正确方法是什么?
最佳答案
This.el 返回一个 DOM Element object它继承自 Event arget .
所以你可以使用addEventListener() :
this.el.addEventListener('drag', function (event) {
//....
})
或者,按照评论中的“mrahhal”建议,分配它:
this.el.ondrag = function(event) {
// ...
}
关于javascript - 如何访问以下JavaScript对象的 "ondrag"方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015570/