32

我正在查看http://digitalbush.com/projects/masked-input-plugin/

我这样称呼它:

$(control).mask('999-999-9999');

如果出现问题,我不希望它丢弃用户输入,例如他们还没有完成

[407-555-____]

如果您在输入这么多后离开该字段,它会清除它。我想留下它,以便他们稍后完成。

我是 jQuery 的新手,我已经查看了他的源代码,但是我找不到任何方法可以做到这一点,也找不到任何方法来编辑它来完成我想要的,因为代码对我来说是神秘的眼睛。

4

7 回答 7

58

将自动清除选项设置为 false。

$(control).mask('999-999-9999', {autoclear: false});
于 2014-02-07T19:54:54.660 回答
46

看起来我应该让整个面具成为可选的:

mask('?999-999-9999')

这样,控件认为用户拥有的东西是“有效的”,我可以继续。即使它不是面具的真正可选部分。

于 2012-03-20T21:31:11.023 回答
2

您应该删除函数中的语句input.val("");checkVal()获得正确的解决方案。

如果您使用的是缩小版,您应该搜索并删除语句:

if(!a&&c+1<i)f.val(""),t(0,k);else
于 2012-07-05T16:23:05.550 回答
0

除了删除 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();
})
于 2013-03-28T17:09:29.993 回答
0

添加占位符可以解决问题。

$(control).mask('999-999-9999');

在面具中添加一个空的占位符。见下文

$(control).mask('999-999-9999', { placeholder: "" });

默认情况下,它将替换输入文本字段上的 _ 。所以如果输入长度是动态的而不是固定的,那么机器人就会留下任何 _ 。

于 2013-04-25T23:08:29.380 回答
0

尝试更新文件 jquery.maskedinput.js

在函数函数 checkVal(allow) 中设置参数允许为真。它对我有帮助。

 function checkVal(allow) {
                    allow = true; ///add this command
//..............
}
于 2013-07-23T13:34:56.997 回答
-2

在插件脚本中寻找 unmask 方法。

$('#checkbox').unmask();
于 2015-01-28T18:12:21.780 回答