简体   繁体   English

如何使用JavaScript屏蔽文本框asp.net中的日期

[英]How to masking date in textbox asp.net with javascript

I am Using textbox for input date user. 我正在为输入日期用户使用文本框。
How to auto masking when user input value date with format mask "dd-MM-yyyy" 用户使用格式掩码“ dd-MM-yyyy”输入值日期时如何自动掩码

Thanks 谢谢

I'm not sure I understand your question, but you can use an ASP.NET CompareValidator to ensure the input is a valid date: 我不确定我是否理解您的问题,但是您可以使用ASP.NET CompareValidator来确保输入的日期是有效的:

<asp:CompareValidator 
    id="cv_date" runat="server"  
    Type="Date" 
    Operator="DataTypeCheck" 
    ControlToValidate="tb_my_textbox"  
    ErrorMessage="Please enter a valid date."> 
</asp:CompareValidator> 

You can't do that with the standard asp.net controls. 您不能使用标准的asp.net控件来做到这一点。 You might try ajax control toollkit, which is a set of ajax controls. 您可以尝试使用ajax控件工具包,它是一组ajax控件。 You can find out about it here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx 您可以在这里找到有关它的信息: http : //www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

Or you could build your own masking using javascript. 或者,您可以使用javascript构建自己的屏蔽。

you can try following JScript: 您可以尝试以下JScript:

$(document).ready(
  function() {
   $('#txtbx').click(
     function() {
         $("#txtbx").mask("999-99-9999");
        });
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM