Javascript Android上PhoneGap应用程序的Webview文本字段中的Maxlength
我试图在Android的PhoneGap中实现maxlength,但无法限制字符,因为它从未获取正确的字符代码。从下面代码中删除密钥的字符代码与任何其他密钥的字符代码相同Javascript Android上PhoneGap应用程序的Webview文本字段中的Maxlength,javascript,android,cordova,maxlength,Javascript,Android,Cordova,Maxlength,我试图在Android的PhoneGap中实现maxlength,但无法限制字符,因为它从未获取正确的字符代码。从下面代码中删除密钥的字符代码与任何其他密钥的字符代码相同 $(".limit-thirtyfive").bind("paste", function(e) { // access the clipboard using the api if (e.keyCode != 8 || e.keyCode != 46) { if ($(
$(".limit-thirtyfive").bind("paste", function(e) {
// access the clipboard using the api
if (e.keyCode != 8 || e.keyCode != 46) {
if ($(this).val().length >= 33) {
$(this).val($(this).val().substr(0, 33));
}
}
});
$('.limit-ten').keyup(function(e) {
if (e.keyCode != 8 || e.keyCode != 46) {
if ($(this).val().length >= 10) {
$(this).val($(this).val().substr(0, 10));
}
}
});
一般长度限制 您只需使用所引用的输入元素的
maxlength
属性即可
<input type="text" maxlength="5"/>
在Nexus 9上无法正常工作。我还想限制一些特殊字符。我试过使用keyup。它还限制了退格&如果用户快速键入,regex将无法正常工作。我在问题中添加了keyup代码
$('your_input').onchange(function(){
$(this).val($(this).val().replace(/a/g, ''));
});