<small id='fx1D5'></small><noframes id='fx1D5'>

    <tfoot id='fx1D5'></tfoot>
  • <i id='fx1D5'><tr id='fx1D5'><dt id='fx1D5'><q id='fx1D5'><span id='fx1D5'><b id='fx1D5'><form id='fx1D5'><ins id='fx1D5'></ins><ul id='fx1D5'></ul><sub id='fx1D5'></sub></form><legend id='fx1D5'></legend><bdo id='fx1D5'><pre id='fx1D5'><center id='fx1D5'></center></pre></bdo></b><th id='fx1D5'></th></span></q></dt></tr></i><div id='fx1D5'><tfoot id='fx1D5'></tfoot><dl id='fx1D5'><fieldset id='fx1D5'></fieldset></dl></div>
  • <legend id='fx1D5'><style id='fx1D5'><dir id='fx1D5'><q id='fx1D5'></q></dir></style></legend>
        <bdo id='fx1D5'></bdo><ul id='fx1D5'></ul>

        为什么悬停在委托事件处理程序中不起作用?

        Why hover does not work in delegated event handlers?(为什么悬停在委托事件处理程序中不起作用?)
          <bdo id='nbZJe'></bdo><ul id='nbZJe'></ul>
        • <small id='nbZJe'></small><noframes id='nbZJe'>

        • <legend id='nbZJe'><style id='nbZJe'><dir id='nbZJe'><q id='nbZJe'></q></dir></style></legend>

                <tbody id='nbZJe'></tbody>
                <tfoot id='nbZJe'></tfoot>
                • <i id='nbZJe'><tr id='nbZJe'><dt id='nbZJe'><q id='nbZJe'><span id='nbZJe'><b id='nbZJe'><form id='nbZJe'><ins id='nbZJe'></ins><ul id='nbZJe'></ul><sub id='nbZJe'></sub></form><legend id='nbZJe'></legend><bdo id='nbZJe'><pre id='nbZJe'><center id='nbZJe'></center></pre></bdo></b><th id='nbZJe'></th></span></q></dt></tr></i><div id='nbZJe'><tfoot id='nbZJe'></tfoot><dl id='nbZJe'><fieldset id='nbZJe'></fieldset></dl></div>
                  本文介绍了为什么悬停在委托事件处理程序中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在动态添加一些元素并在委托事件处理程序中为其分配悬停属性,我在下面的代码中使用了该属性,但它不起作用.

                  I am adding some elements dynamically and assigning a hover property to it in delegated event handlers for which I used below code and it did not work.

                  $(document).on("hover", ".sec_close_fast", function() {
                    $(this).parent('div').parent('div').css("border", "3px solid #000000");
                  });
                  

                  然后我使用 mouseover 并且成功了:

                  Then I used mouseover and it worked:

                  $(document).on("mouseover", ".sec_close_fast", function() {
                    $(this).parent('div').parent('div').css("border", "3px solid #000000");
                  });
                  

                  我想知道为什么 hover 不起作用,而 mouseover 起作用.

                  I would like to know why hover does not work, yet mouseover does.

                  推荐答案

                  函数/事件 .hover 实际上并不是一个事件,而只是 mouseenter 的简写和鼠标离开.来自 docs:

                  The function / event .hover is not actually an event, but just a shorthand for mouseenter and mouseleave. From the docs:

                  .hover() 方法绑定 mouseentermouseleave 事件的处理程序.您可以使用它在鼠标位于元素内时简单地将行为应用于元素.

                  The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element.

                  所以你不能用它来委托"事件.

                  So you cannot use it to "delegate" events.

                  解决方案

                  正如您已经提到的以及文档中提到的那样,您可以使用:

                  As you have already mentioned and as it is mentioned in the docs, you can use:

                  $(static_parent).on("mouseenter mouseleave", element, function (e) {
                    if (e.type == "mouseenter") {
                      // check if it is mouseenter, do something
                    } else {
                      // if not, mouseleave, do something
                    }
                  });
                  

                  这篇关于为什么悬停在委托事件处理程序中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  <i id='QCwqS'><tr id='QCwqS'><dt id='QCwqS'><q id='QCwqS'><span id='QCwqS'><b id='QCwqS'><form id='QCwqS'><ins id='QCwqS'></ins><ul id='QCwqS'></ul><sub id='QCwqS'></sub></form><legend id='QCwqS'></legend><bdo id='QCwqS'><pre id='QCwqS'><center id='QCwqS'></center></pre></bdo></b><th id='QCwqS'></th></span></q></dt></tr></i><div id='QCwqS'><tfoot id='QCwqS'></tfoot><dl id='QCwqS'><fieldset id='QCwqS'></fieldset></dl></div>

                      <bdo id='QCwqS'></bdo><ul id='QCwqS'></ul>
                    • <tfoot id='QCwqS'></tfoot>
                        <tbody id='QCwqS'></tbody>

                      <small id='QCwqS'></small><noframes id='QCwqS'>

                    • <legend id='QCwqS'><style id='QCwqS'><dir id='QCwqS'><q id='QCwqS'></q></dir></style></legend>