主干事件未触发
我知道其他帖子已经与此相关,但到目前为止我看到的答案没有帮助,并且与我的情况略有不同。
window.BotView = Backbone.View.extend
initialize: ->
_.bindAll @, 'alert', 'render'
@el # by calling this here, it initializes the jQuery object
el: $("#submit")
model: Chatbot
events:
"click #submit" : "alert"
alert: ->
console.log("alert called")
alert("event observed")
render: ->
alert("Rendered")
jQuery ->
window.App = new BotView
console.log App.el
我想要的只是当我点击 id
为 submit
的提交按钮时,它会触发 alert
功能。但是,我什至无法让它发挥作用。
我的 #submit
上的简单 click
处理程序无法正常工作的 events
是怎么回事?
我已经仔细检查了我的 el
是否已正确初始化,但即使如此,也没关系,因为点击处理程序没有使用 el
有谁能解释为什么这个简单事件没有触发?
提前致谢
I know other posts have been made regarding this, but so far the answers I've seen have not been helpful, and slightly different from my situation.
window.BotView = Backbone.View.extend
initialize: ->
_.bindAll @, 'alert', 'render'
@el # by calling this here, it initializes the jQuery object
el: $("#submit")
model: Chatbot
events:
"click #submit" : "alert"
alert: ->
console.log("alert called")
alert("event observed")
render: ->
alert("Rendered")
jQuery ->
window.App = new BotView
console.log App.el
All I want is when I click on the submit button with the id
of submit
for it to fire the alert
function. However, I can't even get this to work.
What is going on with the events
that my simple click
handler on #submit
isn't working?
I have double checked that my el
is properly initialized, but even so, it should not matter because the click handler is not using el
Could anyone shed some light on why this simple event is not firing?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您所说的事件中,在 #submit 元素中,查找 ID 为 #submit 并被单击的元素。将其更改为
,它应该可以正常工作。
与上面内容等效的 jQuery 是这样的:
In your events you are saying, in the #submit element, look for an element that gets clicked with the ID of #submit. Change it to
and it should work fine.
The jQuery equivalent of what you have above is this: