2011-07-01 171 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