简体   繁体   English

如何使用JQuery关闭此对话框? 使用Coffeescript?

[英]How do I close this dialog using JQuery? Using Coffeescript?

I'm putting together a new app and, while I normally use JQuery for things like this I'd like to compare it to Coffeescript and choose the right approach. 我正在组装一个新的应用程序,尽管我通常将JQuery用于此类事情,但我想将其与Coffeescript进行比较,并选择正确的方法。 Moreover, I want to make sure I understand how to invoke JQuery correctly using coffeescript. 此外,我想确保我了解如何使用coffeescript正确调用JQuery。

The Dialog is in the following div: 对话框位于以下div中:

<div class="alert-message error">
  <a class="close" href="#">X</a>
  <p>Here is some error text</p>
</div>

The styling puts an 'X' on the right margin of the dialog. 样式在对话框的右边缘放置一个“ X”。 When the user clicks the 'X', the entire div needs to disappear. 当用户单击“ X”时,整个div需要消失。

What JQuery code or Coffescript code would I use to close the dialog? 我将使用什么JQuery代码或Coffescript代码关闭对话框? This dialog could appear on any page in the site. 该对话框可能出现在站点的任何页面上。

Try this: 尝试这个:

$('.close').click(function(){
  $(this).parent().hide(); //finds parent element of clicked .close and hides it
});

Here is samura code using coffeescript 这是使用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()

http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM