What Javascript event is fired when "return" is clicked on an iPad when an input is selected?
Which Javascript event is fired when someone presses the "return" key on an iPad in Safari while an input is selected.
I'm using an input element, but not surrounding it in <form>
tags. I submit the 开发者_开发百科$('#input').value()
when $('#button').click()
occurs. However, I'd like to also like to be able to submit when someone presses "return" on the iPad keyboard.
I was overzealous, here is the answer:
jQuery Event Keypress: Which key was pressed?
You can detect the enter key event in safari on ipad with following way :
<body onkeyup="yourFunction(event)">
then in javaScript
function yourFunction(event) {
var e;
if(event) {
e = event;
} else {
e = window.event;
}
if(e.which){
var keycode = e.which;
} else {
var keycode = e.keyCode;
}
if(keycode == 13) {
alert("do your stuff");
}
};
What about using a <form>
tag and binding your handler to the submit
tag.
$("#myForm").submit(function (event) {
doStuff();
});
It's cleaner and simpler.
精彩评论