2011-09-12 38 views
0

大家好我使用的hoverclick功能的工具提示从这里如何使用悬停,然后单击使用jQuery

ToolTips

现在按我的要求,我想这两个hoverclick结合事件在一个方法中。当hover我不想显示close按钮,但当用户点击我想显示close按钮。我怎么能在一个事件这样做可以在任何帮助我或者任何实例或样品,请分享

我对Click

<script type="text/javascript"> 
    $(document).ready(function() { 
    $('#foobar2').click(function() { 
     var url = $(this).attr('href');  
     $(this).formBubble({ 
     url: url, 
     dataType: 'html', 
     cache: false 
     }); 

     return false; 
    }); 
    }); 
</script> 

尝试本作Tooltip我厌倦了这一点,但没有工作,你可以编辑请

<script type="text/javascript"> 
    $(document).ready(function() { 
    $('#foobar2').bind('mouseover click',function(e) { 
    if(e.Type=='click') 
    { 
    var url = $(this).attr('href'); 

     $(this).formBubble({ 
     url: url, 
     dataType: 'html', 
     cache: false 
     }); 

     return false; 
    } 


     if(e.Type=='mouseover') 
     { 
     var url = $(this).attr('href'); 

     $(this).formBubble({ 
     closebutton:false; 
     url: url, 
     dataType: 'html', 
     cache: false 
     }); 
     $.fn.formBubble.text('hover hover hover hover'); 
    }, function() { //mouse out 
     var thisBubble = $.fn.formBubble.bubbleObject; 

     $.fn.formBubble.close(thisBubble); 
    }); 
     } 

    });}); 
</script> 

您好我试过,但没有奏效

if(e.type=='mouseout') 
{ 
var url = $(this).attr('href'); 
$(this).formBubble.hide() 
} 
+0

发布您的代码... –

回答

3

而不是用绑定:.click(function(){ ... })

绑定:.bind('mouseover click',function(e){ ... })

那么函数里面使用:e.type这将是一个字符串,确定哪个事件类型触发

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

     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> 
+0

我如何禁用关闭悬停 – Vivekh

+0

我想你添加'closeButton:false'到实例化选项对象来禁用关闭按钮。我的答案已更新,以反映这一点。 –

+0

谢谢'比利月亮' – Vivekh