2012-05-10 45 views
3

我在我的頁面中使用了qtip圖像的代碼如下。它通過ajax post顯示每個圖像的動態內容。但它並沒有顯示ThickBox的/ jQuery UI的對話框關閉後qtip並引發錯誤:$(本).qtip不是一個函數

<script src="<%= Config.VirtualDir %>js/jquery.js?v=2" type="text/javascript"></script> 
<script src="<%= Config.VirtualDir %>js/jquery.qtip-1.0.0-rc3.min.js?v=2" type="text/javascript"></script> 

<script type="text/javascript" language="javascript"> 

$(document).ready(function() { 
    BindQtip(); 
}); 
function BindQtip() 
{ 
$('image').each(function(){ 
         $(this).live('click',function() { 
          var $img = $(this); 
          if('<%= objAdminAuth.GetUserID() %>' == $img.attr('data-uid').split('|')[0]) 
          {           
           return false; 
          } 
          if ($img.data('qtip')) {return false;} 
          $(this).qtip({ 
           content: 'Loading...', 
           style: { 
            border: { 
             width: 5, 
             radius: 10 
            }, 
            padding: 0, 
            textAlign: 'center', 
            tip: true, // Give it a speech bubble tip with automatic corner detection 
            name: 'dark' // Style it according to the preset 'cream' style 
           }, 
           hide: 'unfocus', 
           show: { 
            when: 'click', // Don't specify a show event 
            ready: true, // Show the tooltip when ready 
            solo: true 
           }, 
           position: { 
            corner: { 
             tooltip: 'rightMiddle', // Use the corner... 
             target: 'bottomLeft' // ...and opposite corner 
            } 
           }, 
           api: { 
            // Retrieve the content when tooltip is first rendered 
            onRender: function() { 

             var self = this; 
             self.content = ''; 
             $.ajax({ 
              url: window.location.href, 
              type: 'POST', 
              data: 'call=ajax&uid=' + $img.attr('data-uid'), 
              success: function(resp) { 
               self.updateContent(resp); 
              } 
             }); 

            }, 
            onContentUpdate: function() { 
             var self = this; 
            } 
           } 
          }); 
         }); 
         }); 
} 
</script> 

所有的路徑是正確的,其他的東西很好地工作。我錯過了什麼?

任何幫助,將不勝感激。

+0

看起來像你的JS的登記已運行特定的代碼後,正在發生。也許嘗試另一種方法(註冊在主)來鏈接你的JS和測試,看看是否是這樣。 – ericosg

+1

你確定qTip庫加載正確嗎? – JJJ

+0

在BindQtip()之前放置alert()。如果它工作,ericosg是正確的。 – Ashwin

回答

4

看起來您正在使用AJAX在當前文檔中插入HTML,並且此HTML也由顯示初始頁面的腳本生成。這意味着很有可能<script>標籤(如jQuery和qTip的標籤)不僅包含在您的初始頁面中,還包含在您的AJAX響應中。如果這是真的,這些「稍後」的腳本將覆蓋window.$內的內容,其結果與您描述的結果相同。

因此,請檢查您的AJAX是否包含腳本,如果有,請將其刪除。一切都應該正常工作。

+0

你是男人!你搖滾!問題解決了。你有沒有遇到過類似的問題?任何鏈接或參考相同將不勝感激。再次感謝。 :) – user686021

+0

@ user686021:是的,我過去自己也遇到了這個問題。如果你看jQuery源代碼,你會發現它無條件覆蓋'window。$'(它將所有插件和所有狀態都包含在它中) - 然後這些代碼開始一起點擊。 – Jon

1

,我認爲這很可能是犯罪嫌疑人行:

$(this).live('click',function() { 

再來看看文檔中live,這個想法是,你給它一個選擇,而不是一個元素,它接着匹配該選擇器針對達到文檔的給定類型的所有事件。

這種奇怪和困惑語法的live被棄用,取而代之的on在V1.7或更高版本的原因(或我的偏好,delegate,這是可以作爲5.0上的)之一。通過ondelegate,您可以指定要查看事件的實際元素,然後指定一個選擇器以針對委派位的後代進行匹配。

0

你選擇$('image')將選擇所有的HTML元素標記<image>,我不相信有任何...

+0

頁面上有HTML 元素。謝謝。 – user686021

+0

什麼?而你正在使用HTML 6或一些我不知道的奇怪版本?沒有HTML''元素afaik。有一個''或一個' devnull69

+0

其實我正在使用SVG。請檢查[this](http://www.w3.org/TR/SVG/struct.html#ImageElementHrefAttribute) – user686021

相關問題