JQuery apply input mask to field onfocus and remove onblur so to avoid problems with placeholder text

前端 未结 1 1984
别跟我提以往
别跟我提以往 2021-01-21 05:52

I have a date of birth text field:


I\'m using a jQuery plug

相关标签:
1条回答
  • 2021-01-21 06:56

    Reading the plugin code, it should be possible to do this (untested):

    (function($) {
      $(document).ready(function() {
        $('#dob').focus(function() {
          $.mask.definitions['~']='[+-]';
          $(this).mask('99/99/9999');
        }).blur(function() {
          $(this).unmask();
        });
      });
    })(jQuery);
    

    Note that I added (function($){})(jQuery) - I believe it is good practice to wrap all your code this way.

    0 讨论(0)
提交回复
热议问题