访问backbone.js-events上的当前元素?
我知道我可以使用 jQuery 通过 $(this.el)
访问 backbone.js
中的视图元素,但是访问由主干事件绑定处理的元素又如何呢? ?
如何直接从事件处理程序中定位具有 id #button
的单击 div,如下所示?我真的需要为此创建一个子视图吗?
Backbone.View.extend({
el : "#container",
events: {
'click #button' : 'buttonHandler'
},
buttonHandler: function(e) {
// $(this.el)... works as supposed but what about $(my button)?
}
}
I know that I can use jQuery to access the view's element in backbone.js
by $(this.el)
, but what about accessing elements that are handled by backbone's event binding?
How can I target the clicked div with id #button
directly from my event handler, as shown below? Do i really need to create a subview for this?
Backbone.View.extend({
el : "#container",
events: {
'click #button' : 'buttonHandler'
},
buttonHandler: function(e) {
// $(this.el)... works as supposed but what about $(my button)?
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取元素
#button
而不是内部元素,请使用currentTarget
而不是target
。 (来自上面的评论)To get the element
#button
and not an inner element, usecurrentTarget
instead iftarget
. (From comment above)