我使用的是带有触摸屏的jQuery屏幕键盘插件.在我的输入,我想关闭键盘时,我已经达到4个字符。不幸的是,键盘只知道当我达到4个字符,并可以限制最大输入4个字符。用户仍然必须手动关闭键盘。是否有关闭键盘的代码?下面是我的实际脚本:
$('#password').keyboard({
layout: 'custom',
customLayout: {
'default' : [
'C D E F',
'8 9 A B',
'4 5 6 7',
'0 1 2 3',
'{bksp} {a} {c}'
]
},
usePreview : false,
autoAccept: true,
maxLength : 4,
// Prevent keys not in the displayed keyboard from being typed in
restrictInput : true,
// include lower case characters (added v1.25.7)
restrictInclude : 'a b c d e f',
// don't use combos or A+E could become a ligature
useCombos : false,
// activate the "validate" callback function
acceptValid : true,
validate : function(keyboard, value, isClosing){
// only make valid if input is 4 characters in length
if(value.length === 4)
return true; // I want to close the keyboard here
return false;
}
});发布于 2016-05-30 02:38:13
最初,我建议在setTimeout回调中添加一个change,但随后我注意到出现了javascript错误,因为键盘正在关闭,而"keyup“事件仍在触发。
无论如何,我修复了这些错误并添加了一个新的选项 --按如下方式使用它(演示):
$(function() {
$('#password').keyboard({
layout: 'custom',
customLayout: {
'default': [
'C D E F',
'8 9 A B',
'4 5 6 7',
'0 1 2 3',
'{bksp} {a} {c}'
]
},
usePreview: false,
autoAccept: true,
maxLength: 4,
// Prevent keys not in the displayed keyboard from being typed in
restrictInput: true,
// include lower case characters (added v1.25.7)
restrictInclude: 'a b c d e f',
// don't use combos or A+E could become a ligature
useCombos: false,
// activate the "validate" callback function
acceptValid: true,
// option added in v1.25.29
autoAcceptOnValid: true,
validate: function(keyboard, value, isClosing) {
return value.length === 4;
}
});
});https://stackoverflow.com/questions/37515882
复制相似问题