2011-07-01 89 views
4
$(document).keypress(function(event) { 
    // + 
    if (event.which == 43) { 
     // ... 
    } 
} 

HTML觸發按鍵點擊

<input type="button" value="+" name="plus"> 

我怎樣才能觸發與+的按鍵方法單擊按鈕時?

$('input[name="plus"]').click(function(){ 
    // ??? How to go further ??? 
}) 

回答

1
$(document).on('keypress',function(e) { 
    if (e.keyCode == 43 || e.which == 43) { 
     var identifier = e.target.id; 
     console.log(e.target.id); 
     $('#' + identifier).click(); 
    } 
}); 
+0

我需要它反過來:當我點擊按鈕,一個按鍵應該幾乎觸發。 – powtac