2012-02-07 37 views
0

以下代碼是在懸停時生成工具提示...將鼠標懸停在某些文本上,並使用以下代碼jQuery/Ajax - IE不抓取外部文件中的數據?

span class="ttip" rel="#tip_1" 

然後它從外部文件(tooltips.html)中提取帶有tip_1的id的div。麻煩是在IE 7 & 8 - 它只是加載工具提示框 - 不是內部的內容...(就像它不能與tooltips.html文件溝通)

任何想法請嗎?

<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     jQuery('.ttip').hover(function(){ 
      var offset = jQuery(this).offset(); 
      console.log(offset) 

      var width = jQuery(this).outerWidth(); 
      var tooltipId = jQuery(this).attr("rel"); 

      jQuery('#tooltip-cont').empty().load('/tooltips.html ' + tooltipId).fadeIn(500); 
      jQuery('#tooltip-cont').css({ top:offset.top, left:offset.left + width + 10 }).show(); 
     }, function(){ 
      jQuery('#tooltip-cont').stop(true, true).fadeOut(200); 
     }); 
    }); 
</script> 
+0

代碼似乎很好 – mgraph 2012-02-07 12:15:38

+0

我的想法完全是這樣的,在實際的toltips.html文件中似乎有些東西(可能是dodgey的字符),因爲有些工具提示工作不行 – CodeyMonkey 2012-02-07 12:34:21

+0

嘗試刪除'fadeOut'和' fadeIn'然後測試 – mgraph 2012-02-07 12:38:10

回答

1

除非這是當您的問題發佈一個換位的錯誤,你有你的URL的額外空間(.html後):

.load('/tooltips.html ' + tooltipId) 

也許應該是:

.load('/tooltips.html' + tooltipId) 

無關的:你在代碼中進行了很多低效的重新查詢。您應該存儲對已查詢元素的引用,並儘可能使用jQuery的鏈接特性。