![](/img/trans.png)
[英]How do I set a jQuery selector in coffeescript using a variable?
[英]How do I close this dialog using JQuery? Using Coffeescript?
我正在组装一个新的应用程序,尽管我通常将JQuery用于此类事情,但我想将其与Coffeescript进行比较,并选择正确的方法。 此外,我想确保我了解如何使用coffeescript正确调用JQuery。
对话框位于以下div中:
<div class="alert-message error">
<a class="close" href="#">X</a>
<p>Here is some error text</p>
</div>
样式在对话框的右边缘放置一个“ X”。 当用户单击“ X”时,整个div需要消失。
我将使用什么JQuery代码或Coffescript代码关闭对话框? 该对话框可能出现在站点的任何页面上。
尝试这个:
$('.close').click(function(){
$(this).parent().hide(); //finds parent element of clicked .close and hides it
});
这是使用coffeescript的武士代码
$('.close').click() ->
$(this).parent().hide()
// or on 1 line
$('.close').click() -> $(this).parent().hide()
// fat arrow version, not 100% sure on this, typing from ipad
$('.close').click(e) => $(e.target).parent().hide()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.