2010-02-19 63 views
4

我想用qTip傳遞動態參數,但失敗。 my_ajax_controller.php只顯示變量類型,但不顯示q。使用qTip動態內容的動態參數

$('a.menu_help').qtip({ 
    content: { 
     url:'my_ajax_controller.php', 
     data: 'type=help_menu&q='+$(this).attr('id'), 
     method: 'get' 
    }, 
    show: 'mouseover', 
    hide: 'mouseout' 
}); 

然而,Q作品的靜態值:

$('a.menu_help').qtip({ 
    content: { 
     url:'my_ajax_controller.php', 
     data: 'type=help_menu&q=toto', 
     method: 'get' 
    }, 
    show: 'mouseover', 
    hide: 'mouseout' 
}); 

有沒有辦法通過一個動態值的參數數據?

在此先感謝!

弗洛朗

回答

-7

它應該工作,但只是嘗試,看看你傳遞什麼作爲ID,或通過數據收集是這樣的:

 
data : {'type':'help_menu', 'q':id} 

或者

 
$('a.menu_help').qtip({ 
    var id = $(this).attr('id'); 
    alert(id); 
    content: { 
     url:'my_ajax_controller.php', 
     data: 'type=help_menu&q='+ id, 
     method: 'get' 
    }, 
    show: 'mouseover', 
    hide: 'mouseout' 
}); 
+0

這不起作用。 –

+0

我確認這是行不通的,你正在做一個對象定義中的賦值。你會得到一個'丟失:屬性ID'後 –

8

嘗試這樣:

$('a.menu_help').each(function(){ 
    $currentLink = $(this); 
    $currentLink.qtip({ 
     content: { 
      url:'my_ajax_controller.php', 
      data: 'type=help_menu&q='+$currentLink.attr('id'), 
      method: 'get' 
     }, 
     show: 'mouseover', 
     hide: 'mouseout' 
}); 

我沒有測試過這一點,但我已經做了類似的事情。現在找不到它。

+0

此解決方案很好地工作。 – Jeremy

+0

對於許多qtipped元素它還會表現嗎? –

+0

表現不應該有太大的不同,那麼如果你一次性把它們全部打翻。 – Patricia

3

我有同樣的問題,我解決了與此代碼。使用qtip 1.0 rc3和JQuery 1.4.2可以正常工作。 請注意,qtip有和jquery> 1.3的問題。谷歌的相關信息,但很容易修復添加一條線上jquery.qtip.js

$('.username_link').each(function(){ 
    $(this).click(function(){ return false });//JS enabled => link default behavior disabled. Gaceful degradation 
    $(this).qtip({ 
    content: { url: '/users/links', 
       data: { id: $(this).attr('data-id') }, 
       method: 'post' 
      }, 
    show: 'click', 
    hide: 'mouseout' 
    }) 
});