textbox asp.net

时间:2016-06-09 11:42:49

标签: c# asp.net date textbox

我想在用户输入日期时拥有自动日期格式。到目前为止,我得到的是价格值的自动逗号:

<script type="text/javascript" language="javascript">

function Comma(Num) {
    Num += '';
    Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
    Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
    x = Num.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1))
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    return x1 + x2;
}

</script>

你能给我一些类似的代码,其中用户可以选择日期或当他们输入日期时,它会自动添加斜杠或什么?

2 个答案:

答案 0 :(得分:0)

你可以试试html标签输入

<input type="date" runat="server" id="textbox1" />

或者您可以尝试使用AjaxControlToolkit

    <html>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<head>
<!--  your code javascript and Css -->
</head>

<body>
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" />
</body>

答案 1 :(得分:0)

    <html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>


</body>
</html>