如何在鼠标不受控制时隐藏工具提示

时间:2011-09-22 12:00:11

标签: jquery asp.net

大家好我已经为Jquery编写了一个代码,其中Click & Hover个函数都可以用于同一个控件,它可以正常工作。但当我hover我的鼠标在控制工具提示上显示正常时,但如果我将鼠标移出控制工具提示仍保持原样,那么任何人都可以告诉我应该在哪里更改。

这就是我写的

<script type="text/javascript">   
$(document).ready(function() 
{      
$('#foobar9').bind('mouseover click',function(e) {        
if(e.type == 'click'){         
var close = true        
} 
else 
{        
var close = false        
}        
var url = $(this).attr('href'); 
$(this).formBubble({
url: url,         
dataType: 'html',         
cache: false,       
closeButton: close       });       
return false;     });
}); 
</script>

参考网站为http://lyconic.com/resources/tools/formbubble

根据给出的答案我试过这个

 <script type="text/javascript">   
$(document).ready(function() 
{      
$('#A1').bind('mouseover mouseout click',function(e) {        

if(e.type=='mouseout')
{
          $.fn.formBubble.close(thisBubble);
}

if(e.type == 'click'){         // do some click event stuff         
var close = true        
}
else 
{         // do some hover event stuff         
var close = false        
}        
var url = $(this).attr('href'); 
$(this).formBubble({
url: url,         
dataType: 'html',         
cache: false,       
closeButton: close       });       
return false;     });
}); 
</script>

<div>
    <a href="ajaxtest/index10.html" class="ohhai-world" id="A1">HTML-based AJAX (Click)</a>
</div>

2 个答案:

答案 0 :(得分:2)

尝试使用delegate()或只执行mouseout()事件。

$('#foobar9').delegate('body','mouseover mouseout click',function(e) {        
  if(e.type === 'click'){         
      // ...      
  }else if(e.type === 'mouseover'){
      // ...
  }else if(e.type === 'mouseout'){
      //...
  }
});

修改:

我在这里尝试一些东西,并为我工作,检查一下:

html:

    <a href="#" id="A1">Static Text (Hover)</a>

<强> JS:

    $('#A1').bind('mouseover mouseout', function(e) { //hover
        if(e.type == "mouseover"){
            $(this).formBubble({
                closeButton: false
            });
            $.fn.formBubble.text('hover hover hover hover');
        }
        if(e.type == "mouseout"){
            var thisBubble = $.fn.formBubble.bubbleObject;
            $.fn.formBubble.close(thisBubble);
        }
    });

js点击:

 $('#A1').bind('click', function(e) { //hover
        $(this).formBubble({
            alignment: {
            bubble: 'left',
            pointer: 'top-right'
          },
          text: 'text'
        });
      return false;
  });

答案 1 :(得分:1)

这会对你有所帮助

http://api.jquery.com/mouseout/
相关问题