2013-03-06 51 views
0

我有Jquery qtip()函数,并且需要在鼠标悬停链接时获取id。我可以使用jquery .load()来获取页面。不能使用下面的代码。有人知道吗?

下面是我的脚本

$(function() { 
     $(".cabinlink").qtip({ 
content: $("#loadCabin").load("/mysite ." + $(this).attr('id')), 

       show: 'mouseover', 
       hide: 'mouseout', 

       style: { 
        width: 780 
       }, 
       position: { 
        corner: { 
         target: 'LeftBottom', 
         tooltip: 'TopLeft' 
        } 
       } 
      }); 
     }); 

.cabinlink是mousehover链接

<a id="1" href="javascript:void(0)" class="cabinlink" /> 
<a id="2" href="javascript:void(0)" class="cabinlink" /> 
<a id="3" href="javascript:void(0)" class="cabinlink" /> 

loadCabin是开拓qtip箱

<div id="loadCabin"></div> 

修正码股利,能够工作,但需要鼠标两次。第一个mouseover没有结果。有人知道吗?

$(function() { 
     $(".cabinlink").live('mouseover', function() { 

      var id = $(this).attr('id'); 
      var url = "/Mysite ." + id; 
      $(this).qtip({ 
       overwrite: false, 
       content: $("#loadCabin").load(url), 
       show: { ready: true, when: false }, 
       hide: 'mouseout', 
       style: { 
        width: 780 
       }, 
       position: { 
        corner: { 
         target: 'LeftBottom', 
         tooltip: 'TopLeft' 
        } 
       } 

      }); 
     }); 

    }); 
+0

ID不能以数字开头。 – Blender 2013-03-06 01:39:01

+0

我不知道qtip API能够很好地回答你的问题,但我可以告诉你,你没有得到你期望的ID,因为“this”指的是你传递给qtip的选项对象,而不是到被徘徊的元素。我想qtip的一个选项可以让你传递一个回调函数,你可以调用$(this).attr('id')来返回元素的ID。 – 2013-03-06 03:03:47

+0

除此之外,您还需要考虑时间... $(“。cabinlink”)。qtip(...)在页面加载后立即运行,并且只是告诉它使用给定的选项进行初始化。稍后,悬停事件由qtip处理,只有这样,您才会知道哪个元素被悬停。 – 2013-03-06 03:08:37

回答

0

试试这个:

$(".cabinlink").qtip({ 
    onShow: function() { 
     $("#loadCabin").load("/mysite." + $(this).attr('id')) 
    }, 

    show: 'mouseover', 
    hide: 'mouseout', 

    style: { 
     width: 780 
    }, 
    position: { 
     corner: { 
      target: 'LeftBottom', 
      tooltip: 'TopLeft' 
     } 
    } 
}); 

如果不工作,另一回调函数之一可能...查看http://craigsworks.com/projects/qtip/docs/api/#callbacks

+0

无法使您的代码工作。我已经修改了上面的代码,它似乎是这样工作的,但现在问题是我需要两次这样的鼠标悬停。第一个mouseover没有出现任何东西。任何想法 – 2013-03-08 08:15:29

+0

看起来你可能需要自己处理mouseover事件,然后使用qtip API的updateContent方法,如下所示:http://stackoverflow.com/questions/6879907/jquery-ajax-and-qtip-dynamic -内容。请注意,您需要使用$ .get或$ .ajax方法而不是$ .load来使用此方法。 – 2013-03-08 12:29:59

+0

其实我觉得你的情况和链接中的不一样,可能有一个更简单的解决方案,如果我想到的话,我会在这里回复。 – 2013-03-08 12:39:21