javascript - Why doesn't preventDefault() stop focus change after a Tab-keypress? -
i fiddling with preventdefault() , must doing wrong.
$("#input").bind("keypress", function(event) { if(event.which == 9) { event.preventdefault(); alert("you pressed tab."); } }); the tab functionality isn't prevented. what's wrong this?
the keypress event not fired when tab pressed - explains why there no alert, independent of preventing default may do.
changing code utilize keydown allows tab caught , prevents default focus-change (in chrome1, anyway).
$("#input").bind("keydown", function(event) { if(event.which == 9) { event.preventdefault(); } }); 1 tested above in chrome 35 with jquery 1.6-2.1; not work under ko 3.0 library.
javascript jquery keypress preventdefault
No comments:
Post a Comment