2012-05-18 22 views
1

的任何替代方法这是我设计的显示工具提示,而不是写多个jQuery函数

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>FormBubble Examples</title> 
    <link href="stylesheets/formbubble.css" media="screen" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
    <script type="text/javascript" src="jquery.formbubble.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 

      $('#foobar1').hover(function() { //hover 
       $(this).formBubble({ 
        closeButton: false 
       }); 
       $.fn.formBubble.text('hover hover hover hover'); 
      }, function() { //mouse out 
       var thisBubble = $.fn.formBubble.bubbleObject; 

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

      $('#foobar2').hover(function() { //hover 
       $(this).formBubble({ 
        closeButton: false 
       }); 
       $.fn.formBubble.text('Hello'); 
      }, function() { //mouse out 
       var thisBubble = $.fn.formBubble.bubbleObject; 

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

     }); 
    </script> 
</head> 
<body> 
    <div style="width: 220px; margin: auto;"> 
     <p> 
      <a href="#" id="foobar1">Static Text (Hover)</a> 
     </p> 
     <p> 
      <a href="#" id="foobar2">HTML-based AJAX (Click)</a> 
     </p> 
    </div> 
</body> 
</html> 

如果你看到我写的多种功能为每个ID。而不是我可以有一个单一的功能,并显示所需的工具提示

+0

尝试选择所有链接一次,可能使用通用类为您的选择 –

回答

2

我不熟悉的formbubble插件,但你应该能够通过类来连接事件,而不是个别id。试试这个:

<p> 
    <a href="#" id="foobar1" class="formbubble">Static Text (Hover)</a> 
</p> 
<p> 
    <a href="#" id="foobar2" class="formbubble">HTML-based AJAX (Click)</a> 
</p> 
$('.formbubble').hover(
    function() { //hover 
     $(this).formBubble({ closeButton: false }); 
     $.fn.formBubble.text('hover hover hover hover'); 
    }, 
    function() { //mouse out 
     var thisBubble = $.fn.formBubble.bubbleObject; 
     $.fn.formBubble.close(thisBubble); 
    } 
); 
0
$("[title]").hover(function(){ 
      $(this).formBubble({ 
       closeButton: false 
      }); 
      $.fn.formBubble.text('hover hover hover hover'); 
},function() { //mouse out 
      var thisBubble = $.fn.formBubble.bubbleObject; 

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

这是类存在的原因之一。

$('.tooltip').hover(function(){ //hover 
    $(this).formBubble({ closeButton: false }); 
    $.fn.formBubble.text('hover hover hover hover'); 
}, function(){ //mouse out 
    var thisBubble = $.fn.formBubble.bubbleObject; 
    $.fn.formBubble.close(thisBubble); 
}); 

然后,你只是给每个元素你想有一个工具提示这个类。

<p> 
    <a href="#" id="foobar1" class="tooltip">Static Text (Hover)</a> 
</p> 
<p> 
    <a href="#" id="foobar2" class="tooltip">HTML-based AJAX (Click)</a> 
</p>