【问题标题】:Masking phone number using TextBoxFor使用 TextBoxFor 屏蔽电话号码
【发布时间】:2014-08-11 10:06:28
【问题描述】:

我想使用 html 助手 (TextBoxFor) 屏蔽电话号码

这是我的代码

  Model :
        [Required(ErrorMessageResourceType = 
         typeof(ProcRec.Ressources.Candidat.ErreurValidation),
         ErrorMessageResourceName = "num_tel_obligatoire")]
         [RegularExpression(@"[0][6]\-\d{2}\-\d{2}\-\d{2}\-\d{2}$",
        ErrorMessageResourceType =   
        typeof(ProcRec.Ressources.Candidat.ErreurValidation),
         ErrorMessageResourceName = "num_tel_faux")]   
         public string num_tel { set; get; }

查看:

     <script type="text/javascript">
      jQuery(function($){
        $("#date").mask("99/99/9999");
       $("#num_tel").mask("(999) 999-9999");
       $("#tin").mask("99-9999999");
       $("#ssn").mask("999-99-9999");
      });

        </script>

       <td>@Html.LabelFor(model => model.num_tel)</td>
       <td>@Html.TextBoxFor(model => model.num_tel)</td>

验证正常

但说到面具,我什么也得不到

他们是我得到的结果

。 . . . . . .

【问题讨论】:

  • 我试过了,但它不能用 textboxfor... 我想我错过了什么,但我不知道在哪里
  • 您是否遇到任何控制台错误?
  • 尝试将javascript代码放入$(document).ready(function(){/* put here */});
  • jQuery(function($){ ....}); 应该像 (function($){...})(jQuery);... 我不确定,但我看到了 this 链接。

标签: javascript jquery asp.net-mvc jquery-mask


【解决方案1】:

我找到了解决办法。
问题是我没有安装jQuery.MaskedInput插件。

要安装jQuery.MaskedInput,请在包管理器控制台中运行以下命令:

PM> Install-Package jQuery.MaskedInput -Version 1.3.1 

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 2012-07-24
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2011-05-08
    • 2021-01-10
    相关资源
    最近更新 更多