I have the following which works fine in Chrome 22 but is giving me an error in Firefox 16:
$('#search-query').on('keyup',function(){
e=window.event;
if(e.keyCode===13){
alert('that was a return');
}
How would I make this work in a cross-browser way?
thx
use jQuery wrapper event. firefox don't support window.event
$('#search-query').on('keyup',function(e){
if(e.keyCode===13){
alert('that was a return');
}
Firefox does not support window.event
Try this instead
$('#search-query').on('keyup',function(e){
var evt = e || window.event;
var keyPressed = evt.which || evt.keyCode;
if(keyPressed ===13){
alert('that was a return');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.