How do i replace a key up keyCode with another in jQuery?
I currently have a table which only has a single editable column. I开发者_如何学运维 have a jQCuery change() event associated with the column's input controls to prevent any non numeric keys being pressed, other than tab / delete / backspace.
I would like to replace the Enter key with a Tab press.
Can someone please show me the relevant statement to replace the keyCode based on the Enter character being intercepted?
You can't replace it, but you can handle it, like this:
$(".myField").keyup(function(e) {
if(e.keyCode == 13) {
$(this).closest("tr").next("tr").find("input").focus();
return false;
}
});
Just modify the $(this).closest("tr").next("tr").find("input").focus();
(currently going to the next row) portion to whatever your layout is, to find the next element you want to move to and focus it.
Since you are capturing the key's anyway, why not just move focus when the enter key is used rather than try to change keystrokes.
精彩评论