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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8910983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:57:17  来源:igfitidea点击:

How to masking date in textbox asp.net with javascript

javascriptasp.nethtml

提问by Yusan Susandi

I am Using textbox for input date user.
How to auto masking when user input value date with format mask "dd-MM-yyyy"

Thanks

我正在使用文本框输入日期用户。
当用户使用格式掩码“dd-MM-yyyy”输入值日期时如何自动掩码

谢谢

采纳答案by Brissles

I'm not sure I understand your question, but you can use an ASP.NET CompareValidatorto ensure the input is a valid date:

我不确定我是否理解您的问题,但您可以使用 ASP.NETCompareValidator来确保输入是有效日期:

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

回答by Nick Bray

You can't do that with the standard asp.net controls. You might try ajax control toollkit, which is a set of ajax controls. You can find out about it here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

使用标准的 asp.net 控件无法做到这一点。您可以尝试使用 ajax 控件工具包,它是一组 ajax 控件。你可以在这里找到它:http: //www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

Or you could build your own masking using javascript.

或者您可以使用 javascript 构建自己的掩码。

回答by Dhaval Shukla

you can try following JScript:

您可以尝试以下 JScript:

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