如何在Alertify.js提示符上附加一个掩码

how to applique a mask on an Alertify.js prompt

本文关键字:掩码 一个 Alertify js 提示符      更新时间:2023-09-26

是否有办法在Alertify.js提示符上贴花掩码?

我需要像这样添加一个jquery mask a:

$('document').ready(function(){
  $('.car_number').mask('(SSS-0000');
  });

在像这样的alertify.js提示符上:

alertify.prompt( 'test', 'Insert a car number', '', function(evt, value) {
               if(value) {
                   getVal(value);
                   }
                }
               , function() {})
}

得到如下输出:

PCT-5077

欢迎任何帮助

只要可以访问DOM,就可以做任何想做的事情:

function show(){
  var prompt = alertify.prompt();
  prompt.set({
   'onshow': function(){
    var input = this.elements.content.querySelector('input');
    //customize the input as you please
    $(input).mask();
    },
    'onclose':function(){
      var input = this.elements.content.querySelector('input')
      //clear the customization as this is a singleton.
      //$(input) 
    }
  })
  .show();
}

但是请记住,默认的AlertifyJS提示符是一个单例,所以最好在关闭时清除自定义