0

我有这个:

<div id='hasHover'>
  <div id='inner-button' style='display:none'>Click</div>
</div>

$('#hasHover').hover(function(){
  $('inner-button').toggle();
});

这工作正常。但是,当我将鼠标移到按钮上时,按钮会消失(或快速闪烁)。当鼠标悬停在div(包括子div)上时,如何确保按钮保持不变?

4

2 回答 2

1
$('#hasHover').hover(function(e) { // <-- Create event argument
  if(e.target.id == "hasHover") { // <-- Check the ID of the div on which event fired
     $('#inner-button').toggle(); // <-- You missed # here
     return false;
  }
  else {
     return false;
  }
});
于 2013-03-01T04:47:10.807 回答
0

检查目标ID

$('#hasHover').hover(function(e) {
   if(e.target.id = "hasHover") {
      $('inner-button').toggle();
   return false;
   }else {
    return false;
   }
}); 
于 2013-03-01T04:48:22.723 回答