2012-02-23 13 views
0

這使我瘋狂,我看不到問題。使用jQuery(我與v 1.6.2 btw,因爲它在CMS內),我試圖通過點擊鏈接顯示內容的div。在jQuery中使用click()時發生event.layerX錯誤

這裏是我的HTML:

 <div id="vl-hcp" class="venue"> 
      <h1>Title of venue</h1> 
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor.</p> 
     </div> 

<div class="venuesScroller">  
<a href="javascript:void(0);" class="vl-hcp"><span>Title of venue</span></a> 
</div> 

這裏是我的jQuery:

$('.venuesScroller a').click(function(){ 
     // Make only currently clicked link active and hide other info boxes 
     $('.venuesScroller a').removeClass('active'); 
     $('.venue').addClass('hidden'); 

     // Make link active and go through cases for showing text 
     $(this).addClass('active'); 
     if($(this).hasClass('vl-hcp')) { 
      $('#vi-hcp').removeClass('hidden'); 
     } 
}); 

但沒有類是在會場的div改變,當我點擊鏈接,並在Chrome(17.0版本.963.56),我得到錯誤:

event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.

任何人都可以看到問題是什麼?我真的被困在這裏。

感謝,

奧蘇

+0

這不是一個錯誤,它的警告。 – 2012-02-23 21:24:14

回答

1

這是不是一個錯誤,這是一個警告。

當jQuery正常化event對象時,它遍歷它可能具有的所有屬性,當它觸及layerXlayerY時,Chrome的JS引擎會引發警告。

如果問題是,hidden類不是從#vl-hcp刪除,這是因爲一個錯字:

$('#vi-hcp').removeClass('hidden'); 

應該

$('#vl-hcp').removeClass('hidden'); 
+0

確實如此,但即使我使用Alexander的技巧刪除警告,我的代碼仍然無法正常工作。有什麼理由不起作用嗎?它不適用於Safari,也不適用於Mac上的Firefox 9 ... – Osu 2012-02-23 21:49:13

+0

@Osu我更新了我的答案 – Shad 2012-02-23 21:53:30

+0

我感覺非常愚蠢。感謝您指出,這是一個漫長的夜晚! – Osu 2012-02-23 21:56:14

0

我用下面的代碼here到修復這些警告。這是避免更新jQuery的解決方法。

(function(){ 
    // remove layerX and layerY 
    var all = $.event.props, 
     len = all.length, 
     res = []; 
    while (len--) { 
     var el = all[len]; 
     if (el != 'layerX' && el != 'layerY') res.push(el); 
    } 
    $.event.props = res; 
}()); 

更多信息可以在相同的referring question中找到。

+0

感謝您的這一點,我看到了其他帖子,並嘗試過,但我仍然無法讓我的jQuery代碼工作。你能看出它爲什麼可能不起作用嗎?謝謝 – Osu 2012-02-23 21:46:33

相關問題