【问题标题】:hover in hover jquery/javascript悬停在悬停 jquery/javascript
【发布时间】:2015-02-06 07:46:03
【问题描述】:

我有一个悬停在悬停状态,当我悬停第一个元素 #rezultat 时,它可以正常工作,每次悬停该元素时它都会显示 id,但是当我悬停它的子元素时,它会显示子元素的 id我之前悬停父元素的所有时间的总和。为什么?解决办法是什么?

$("#rezultat").hover(function(event){
       console.log($(this).attr("id"));
       $("#rezultat").children().hover(function(){
             console.log($(this).attr("id"));
       });
});

【问题讨论】:

  • 看看租它是ibpm.net78.net/posteazasubiectnou.php 你可以在控制台看到结果
  • @jamal 当其他人在同样的事情上需要帮助时,不要强迫人们访问您可能在 10 年内无法使用的网站。而是创建一个 JSFiddle。
  • 我不知道JSFiddle是什么。我专门创建了这个来表明它不起作用。我没有强迫你去那里。如果你不想帮助,不要帮助

标签: javascript jquery


【解决方案1】:

你在找这个吗:

       $("#rezultat").hover(function(event){
   console.log($(this).attr("id"));
   $("#rezultat").children().hover(function(event){
         event.preventDefault();
         console.log($(this).attr("id"));
   });
 });

【讨论】:

【解决方案2】:

将两个函数调用分开:

$("#rezultat").hover(function(event) {
    console.log("parent: " + $(this).attr("id"));
});

$("#rezultat").children().hover(function() {
    console.log("child: " + $(this).attr("id"));
});

否则,每次在 #rezultat 上触发悬停事件时,您都会为所有子项分配新的 onHover 事件。

这是一个工作示例:http://jsbin.com/vadameyexi/1/edit?html,js,console,output

【讨论】:

  • 它不起作用。看看租它是 ibpm.net78.net/posteazasubiectnou.php 你可以在控制台看到结果
  • 它有效。我添加了一个工作示例的链接。再次检查您的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 2014-06-19
  • 1970-01-01
相关资源
最近更新 更多