3
イベントはワイルドカードセレクタでうまくいきますが、セレクタに特定のIDを使用すると失敗します。シンプルなCoffeeScriptとjQueryイベントの奇妙な問題
これは動作します:
$("*").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>
私は仕事に、このためのCoffeeScriptで何かが足りません?多分、jQueryセレクタはCoffeeScriptで書式が違うでしょうか?
これは私のアプリケーションがありますレンダリングのJavascript(ページを提供するときRailsはJSへのCoffeeScriptを変換):
(function() {
$("#tell-a-friend").click(function() {
console.log("works");
return $("#tellafriend").dialog({
modal: true,
buttons: {
Ok: function() {
return $(this).dialog("close");
}
}
});
});
}).call(this);
ああ、私を冗談にしているのですが、私は '$(document).ready()'ビットを忘れていました。テスト。編集:はい、それは問題でした。私の一部で大規模なbrainfart。これはいつも私が新しい領域(coffeescript)にいるときに起こります。私は基本を忘れています。 –