2013-05-14 48 views
0

所以我有一個Firefox的問題與onkeydown事件的圖像按鈕。我不想讓按鈕動作觸發,直到他們放開按鈕。所以這對IE和Chrome都很有用。我無法弄清楚爲什麼它在Firefox中不起作用(20.0.1)。以下是圖像按鈕的代碼:ASP.NET - onkeydown事件不工作在Firefox

<asp:ImageButton ID="btnButton1" ImageUrl="/images/target.png" runat="server" 
Height="75" Width="75" onkeydown="return false;" onkeyup="ButtonClick()" /> 

所以看起來的onkeyup在所有瀏覽器的工作完美,但的onkeydown不希望在Firefox的工作,我無法弄清楚。任何幫助將不勝感激。

我不知道它是否會有所幫助,但我會後我的JavaScript函數的onkeyup還有:

function ButtonClick() { 
    document.getElementById('<%=btnButton1.ClientID %>').click(); 
    return true; 
} 
+0

Theres另一個話題涉及到Firefox的這個問題!看看這裏:http://stackoverflow.com/questions/642040/firefox-onkeydown-detect-pressed-key!希望它幫助你 – Fals 2013-05-14 18:16:30

回答

-1

請嘗試使用

function ButtonClick() { 
    document.getElementById('<%#btnButton1.ClientID %>').click(); 
    return true; 
} 
+0

我很欣賞答案,但是我的代碼中的那部分在所有瀏覽器上都能正常工作。問題是onkeyup =「return false;」不想在Firefox上工作。適用於Chrome和IE。因此,在Firefox中,他們可以按住按鈕,每次點擊也可以計算2次點擊。 – j5juice 2013-05-14 15:31:20

0

嗯,你可以試試嗎?

$(document).on("keypress", ".chat-input ", function (val) { 
    clearTimeout(timer); 
    timer = setTimeout(function() { 
     //codes 
    }, 1); 
}).on('keydown', function (e) { 
    if (e.keyCode == 8 || e.keyCode == 13) { 
     $('.chat-input').trigger('keypress'); 
    } 
});