Mottie 的虚拟键盘在验证为真时关闭
Mottie's Virtual Keyboard close on validate true
我正在使用带触摸屏的 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;
}
});
最初,我打算建议在 change
回调中添加一个 setTimeout
,但后来我注意到弹出 javascript 错误,因为键盘正在关闭并且 "keyup" 事件仍在触发。
无论如何,我修复了这些错误并添加了一个新的 autoAcceptOnValid
option - use it as follows (demo):
$(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;
}
});
});
我正在使用带触摸屏的 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;
}
});
最初,我打算建议在 change
回调中添加一个 setTimeout
,但后来我注意到弹出 javascript 错误,因为键盘正在关闭并且 "keyup" 事件仍在触发。
无论如何,我修复了这些错误并添加了一个新的 autoAcceptOnValid
option - use it as follows (demo):
$(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;
}
});
});