jQuery inputmask允许保留占位符文本 [英] jQuery inputmask allowing placeholder text to remain

查看:165
本文介绍了jQuery inputmask允许保留占位符文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/RobinHerbots/jquery.inputmask并将掩码应用于所有具有"date"类的文本框.我遇到的问题是,如果用户将占位符中的一个或多个字母留在原处,它将被接受.例如,用户输入10,然后单击该字段,然后该字段将保留10/dd/yyyy.如何停止这种行为?我想防止用户在这种情况下离开该字段.

I am using the inputmask from https://github.com/RobinHerbots/jquery.inputmask and applying the mask to all textboxes with class "date". The problem I am having is that if the user leaves one or more of the letters from the placeholder in place, it will be accepted. For example, the user enter 10 but then clicks out of the field and the field is left with 10/dd/yyyy. How can I stop this behavior? I want to prevent the user from leaving the field when it looks like this.

这是面具的jQuery:

here is the jQuery for the mask:

$('.date').inputmask("mm/dd/yyyy", { "placeholder": "mm/dd/yyyy" })

推荐答案

您可以使用onincomplete事件在未完成时清除输入

you could use the onincomplete event to clear the input when ever is not complete

演示

$('.date').inputmask("mm/dd/yyyy", 
          { 
              "placeholder": "mm/dd/yyyy",
              onincomplete: function(){
                  $(this).val('');
              }
          }
  );

这篇关于jQuery inputmask允许保留占位符文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆