简体   繁体   English

向我解释这个Javascript片段

[英]Explain this fragment of Javascript to me

I am newbie to jQuery, can someone explain what this code does: 我是jQuery的新手,有人可以解释这段代码的作用:

$("#currency form").submit(function(e) {

        triggers.eq(1).overlay().close();
        return e.preventDefault();
    });

The first line begins a function that handles the submit event of all form tag(s) in the element with ID currency . 第一行开始一个函数,该函数处理具有ID currency的元素中所有form标记的submit事件。
Documentation : Selectors , submit event 文档选择器submit事件

The second line closes an overlay in the second element in the triggers variable. 第二行关闭triggers变量中第二个元素的叠加层。
Documentation : eq method , overlay plugin 文档eq方法叠加插件

The third line tries to prevent the submit, but isn't completely correct. 第三行试图阻止提交,但不完全正确。 (It should be e.preventDefault(); and/or return false; ) (它应该是e.preventDefault();和/或return false;
Documentation : event.preventDefault , event handlers 文档event.preventDefault事件处理程序

triggers = a jQuery object triggers =一个jQuery对象

triggers.eq(1) = get the second element from the matched elements inside the jquery object triggers.eq(1) =从jquery对象内的匹配元素中获取第二个元素

triggers.eq(1).overlay() = get the overlay instance (a plugin) on the second element triggers.eq(1).overlay() =获取第二个元素上的叠加实例(插件)

triggers.eq(1).overlay().close() = close the overlay. triggers.eq(1).overlay().close() =关闭叠加层。

return e.preventDefault() ; return e.preventDefault() ; = prevent the default action (form submission) =阻止默认操作(表单提交)

On the submit event of the form, it will: 在表单的提交事件中,它将:

  1. Get the second element in the triggers collection (of jQuery elements). 获取触发器集合中的第二个元素(jQuery元素)。
  2. Get the overlay on that element. 获取该元素的叠加层。
  3. Close that overlay. 关闭那个叠加层。
  4. Prevent the submit event from bubbling to the parent handler. 防止提交事件冒泡到父处理程序。

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

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