2013-07-30 160 views
0

我試圖創建一個表,其中有幾個鏈接出現onHover並隱藏onleave。我實現了這兩個函數JavaScript onmouseleave和onmouseenter在Firefox和IE9中工作,但不在Chrome中?

<script type="text/javascript"> 
    function hide(cls, no) { 
     var select = '.' + cls + no; 
     $(select).hide(); 
    } 
    function show(cls, no) { 
     var select = '.' + cls + no; 
     $(select).show(); 
    }   
</script> 

和我的HTML代碼

<tr onmouseenter="show('inv', 1)" onmouseleave="hide('inv', 1)" > 
    <td width="30%"> 
      <a class="single_image" href="img/img1-big.png"><span class="icon-picture"></span> Image1.jpg</a> 
     </td> 
     <td width="40%" align="center"> 
     <div class="button-col"> 
      <a href="#" class="inline-buttons inv1"><span class="icon-pencil"></span> Rename </a> 
      <a href="#" class="inline-buttons inv1"><span class="icon-arrow-down"></span> Download </a> 
      <a href="#" class="inline-buttons inv1"><span class="icon-share"></span> Share </a> 
      <a href="#" class="inline-buttons inv1"><span class="icon-trash"></span> Delete </a> 
     </div> 
    </td> 
</tr> 

我使用的引導框架。 此代碼完美適用於IE9和Firefox

+0

是否使用:關於這裏COMPAT http://api.jquery.com/hover/

更多信息任何引導的JavaScript?在這種情況下,jQuery已經是必需的了,當你這樣做時,你可以從中受益。 – David

+0

我不太瞭解jquery。不,我沒有使用jQuery。但是,我已經從code.jquery.com導入了jquery文件。 –

回答

2

mouseentermouseleave事件在Chrome(和其他瀏覽器)中不可用。你應該使用一個JavaScript框架來規範化這個,比如jQuery。

使用jQuery,你可以試試:

<tr data-no="1" data-cls="inv"> 

和:

$(function() { 
    $('tr').each(function() { 
     var $target = $('.' + $(this).data('cls') + $(this).data('no')); 
     $(this).hover(
      function() { $target.show(); }, 
      function() { $target.hide(); } 
     ); 
    }); 
}); 
.hover()

更多信息:https://developer.mozilla.org/en-US/docs/DOM/DOM_event_reference/mouseenter#Browser_compatibility

+0

您可以在JQuery中幫助編寫這樣的東西,我只需要一個例子來接近我的解決方案。我在JS方面並不是很熟練。 –

+0

@UsmanTahir當然,請參閱我的編輯。 – David

+0

工作:) 只需要現在添加鼠標離開。 謝謝 –

相關問題