2013-10-31 41 views

回答

0

使用Javascript禁用縮略圖上的onclick()事件並保持onmouseover()事件的效果。

閱讀以下鏈接:http://www.htmlgoodies.com/beyond/javascript/article.php/3470771

我們假設你的縮略圖圖像。 下面將是你的HTML:

<img id="thumbnail" src="sourcefile.jpg" OnMouseOver="MouseOverEvent()" OnClick="return false;"/> 

下面將是你的JavaScript元素(你可以在HTML文件中有一個標籤添加它)

<script> 
function OnMouseOverEvent() 
{ 
//you can set your effects here 
} 
</script> 
+0

我剛纔說,但我不知道如何在我的網站中設置。你能用我的網站元素給我一個例子嗎? –

+0

我編輯了我的答案。讓我知道它是否有幫助。 –

0

您目前使用jQuery在該網頁上。也許這可以工作。

jQuery('div.thumbail > a').unbind('click'); 
0

從標籤

刪除HRF
<a href="http://srougi.biz/gb/portfolio/acessorios/" title="Acessórios"> 

變化

<a title="Acessórios"> 
0

正如其他人所說,你不能處理點擊CSS事件。如果您想爲所有的縮略圖的禁用點擊,使用jQuery(爲簡單起見),你可以直接添加到您的網站的頭:

<script src="path/to/your/jquery.js"></script> 

<script> 

    (function($) { 

     // find all 'a' elements inside of the 'thumbnail' class 
     var block_click = $('.thumbnail').find('a'); 

     // function to create the new behavior you want to achieve 
     function prevent_default_click_behavior(e) { 

      // You can use this 
      e.preventDefault(); 

      // Or this method 
      return false; 

     } 

     // then, bind the desired behavior to the elements click event 
     block_click.on('click', prevent_default_click_behavior); 

    })(jQuery); 

</script> 

如果要禁用一些圖片的鏈接,爲其他人留下它,你可以使用不同的類來指定這兩者之間的關係。一個簡單的實現可能是這個樣子:

<div class="thumbnail stop-click"> 
    <a href="#"> 
    <img src="src/to/image/jpg" alt=""> 
    </a> 
</div> 

現在使用JavaScript,我可以輕鬆地說:「用我的行爲」爲我所有的縮略圖,用「頭痛醫頭,點擊」類的。

<script> 

    (function($) { 

     // all 'a' elements inside the 'thumbnail' class that also has the 'stop-click' class 
     var block_click = $('.thumbnail.stop-click').find('a'); 

     // function to create the new behavior you want to achieve 
     function prevent_default_click_behavior(e) { 

      // You can use this 
      e.preventDefault(); 

      // Or this method 
      return false; 

     }  

     // then, bind the desired behavior to the elements click event 
     block_click.on('click', prevent_default_click_behavior); 

    })(jQuery); 

</script>