I need an input (type = 'text') to send the results to my server in order to check the availability of what was entered by the user.
I use a delegate to add event handlers to elements:
$(document).delegate('#signup', 'pageshow', function() {
var keydown = function(e) {
e = e || window.event;
var char = e.which || e.keyCode;
if (char == 8) {
$(".pagemessage").text("Pressed: '<BACKSPACE>'");
appcheckDomainOnKeyDown();
}
return true;
};
var keyup = function(e) {
e = e || window.event;
var char = e.which || e.keyCode;
if (char == 8) {
appcheckDomainOnKeyUp();
}
return true;
};
var keypress = function(e) {
e = e || window.event;
var char = e.which || e.keyCode;
var str = String.fromCharCode(char);
$(".pagemessage").text("Pressed: '" + str +"'");
if (/[a-zA-Z0-9-\._]/.test(str) || char == 8 || char == 9) {
appcheckDomainOnKeyDown();
appcheckDomainOnKeyUp();
return true;
}
return false;
};
Key switches work fine on my desktop, but not on a mobile device. Hopefully you will see that I am trying to resolve certain characters in a field (and the reverse space for deleting characters).
Due to the fact that I do not see an update to the pagemessage element, "keypress" does not seem to fall into the trap. I tried to handle this in keyup / keydown, but I'm not sure how to use the shiftKey bits to get the actual character - for example, pressing + 5 will give "%", however in keydown it returns shiftKey and 5.
, , "keypress" , "tap", .
"keypress" , , backspace .
, :
var inputEV = 'oninput' in window ? 'input' : 'keyup';
$("#new_domain").off(inputEV);
$("#new_domain").on(inputEV, function (e) {
keydown(e);
keyup(e);
});
, .
"", , ... .
, , - :)
- , , ?
, , Android- (HTC one Nexus 5)