除了删除 checkVal() 中的 input.val("") 之外,您还可以更改对 clearBuffer 的调用。在原始代码中是: clearBuffer(0, len); 删除所有用户输入。如果您将其更改为 clearBuffer(lastMatch + 1, len); 将显示用户输入,然后是完成正确输入仍需要的掩码占位符。
我还在 .bind 中添加了一条用户消息。这对我们有用,因为我们将 MaskedInput 用于一种类型的输入。我正在检查任何比位置 7 更远的输入,因为这是用户输入开始的地方。
这是我所做的:
.bind("blur.mask", function() {
// find out at which position the checkVal took place
var pos = checkVal();
// if there was no input, ignore
if (pos <=7) {input.val(""); clearBuffer(0, len);}
// if the user started to input something, which is not complete, issue an alert
if (pos > 7 && pos < partialPosition) alert("Tell the user what he needs to do.");
if (input.val() != focusText)
input.change();
})