2010-12-01 72 views
1

& LTA ID =「鏈接1的」 href =「鏈接1」 & gtlink1 & LT/A & GTjQuery中,如何讓鼠標右鍵單擊具有左擊相同的行爲

什麼,我想意識到:當我右鍵單擊或左鍵單擊這些鏈接時,我都會轉到鏈接的頁面。我有幾個問題:

  1. 我該如何從firefox和IE中的jquery獲得href?

  2. 我怎麼能確定在Firefox和IE中的鼠標事件,該event.which在Firefox和IE中

    不同behaivors

非常感謝您

+2

不要繼續詢問[相同的問題再次](http://stackoverflow.com/questions/4316996/in-jquery-how-to-make-the-right-click-of-the-mouse-有同樣的行爲),更新你以前的問題。 – 2010-12-01 00:37:59

回答

1

要獲得href,這是a標記的屬性,可以使用

var the_href = $('#link1').attr('href'); 

這適用於所有主流瀏覽器。

1
$('#element').mousedown(function(event) { 
    switch (event.which) { 
     case 1: 
     alert('Left mouse button pressed'); 
     break; 
     case 2: 
     alert('Middle mouse button pressed'); 
     break; 
     case 3: 
     alert('Right mouse button pressed'); 
     $(this).click(); 
     event.preventDefault; 
     break; 
    } 
}); 

(從大量舉債:How to distinguish between left and right mouse click with jQuery) 我不知道你的#1

添加@Camilo迪亞斯的回答我的,所以你可以有一個完整的答案,既您的問題的含義: for#2:var the_href = $('#link1').attr('href')

我聲明的答案將完成您的目標,而不需要href屬性。

相關問題