Javascript 简单CoffeeScript和jQuery事件的奇怪问题
该事件在通配符选择器上很好地激发,但如果我为选择器使用特定ID,则会失败 这项工作:Javascript 简单CoffeeScript和jQuery事件的奇怪问题,javascript,jquery,events,coffeescript,Javascript,Jquery,Events,Coffeescript,该事件在通配符选择器上很好地激发,但如果我为选择器使用特定ID,则会失败 这项工作: $("*").click -> console.log "entered event." $("#tellafriend").dialog modal: true buttons: Ok: -> $(this).dialog "close" 然而,这并不是: $("#tell-a-friend").click -> console.lo
$("*").click ->
console.log "entered event."
$("#tellafriend").dialog
modal: true
buttons:
Ok: ->
$(this).dialog "close"
然而,这并不是:
$("#tell-a-friend").click ->
console.log "entered event."
$("#tellafriend").dialog
modal: true
buttons:
Ok: ->
$(this).dialog "close"
以及我的相关HTML:
<ul class="actions">
<li><a href="#">Home</a></li>
<li>|</li>
<li><a href="#" id="tell-a-friend">Tell a Friend</a></li>
</ul>
是否可能在DOM完全加载之前执行代码。尝试将其包装到文档就绪处理程序中,以便在DOM完全加载后应用任何单击处理程序。实际上,它可能只在body元素上执行,因为在执行脚本时,body元素是唯一可用的元素。哦,你一定是在开玩笑,我忘记了
$(document).ready()
位。测试。编辑:是的,这就是问题所在。就我而言,这是一个巨大的脑屁。这总是发生在我在新的领域(咖啡脚本)我忘记了基本的。
(function() {
$("#tell-a-friend").click(function() {
console.log("works");
return $("#tellafriend").dialog({
modal: true,
buttons: {
Ok: function() {
return $(this).dialog("close");
}
}
});
});
}).call(this);