Javascript 在文本框中输入的日期必须反映在其他文本框中

Javascript 在文本框中输入的日期必须反映在其他文本框中,javascript,asp.net,vb.net,datepicker,Javascript,Asp.net,Vb.net,Datepicker,我有两个表。在我的第一个表中,我有一个带有日期选择器的文本框(txt1)。 在我的第二个表中,我有5个类似的文本框(txt2、txt3、txt4、txt5、txt6)和日期选择器 我的标准是 最初,所有文本框必须显示今天的日期,如果我在第一个表中更改日期,则第二个表中的所有文本框必须更改为我在第一个表中选择的日期。 我需要一个VB代码或jave脚本来做这件事 我已经完成了显示今天日期的操作,但无法为另一个案例编写代码 If txt1.Text = "" Then

我有两个表。在我的第一个表中,我有一个带有日期选择器的文本框(txt1)。 在我的第二个表中,我有5个类似的文本框(txt2、txt3、txt4、txt5、txt6)和日期选择器

我的标准是

最初,所有文本框必须显示今天的日期,如果我在第一个表中更改日期,则第二个表中的所有文本框必须更改为我在第一个表中选择的日期。 我需要一个VB代码或jave脚本来做这件事

我已经完成了显示今天日期的操作,但无法为另一个案例编写代码

If txt1.Text = "" Then
                txt1.Text = Format((Date.Today), "dd-MMM-yyyy")
                If txt1.Text <> "" Then
                    txt2.Text = txt1.Text
                    txt3.Text = txt1.Text
                    txt4.Text = txt1.Text
                    txt5.Text = txt1.Text
                    txt6.Text = txt1.Text
                End If
            End If
如果txt1.Text=”“,则
txt1.Text=格式((Date.Today),“dd-MMM-yyyy”)
如果是txt1.Text“”,则
txt2.Text=txt1.Text
txt3.Text=txt1.Text
txt4.Text=txt1.Text
txt5.Text=txt1.Text
txt6.Text=txt1.Text
如果结束
如果结束
在页面加载时添加此选项

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            txt1.Text = DateTime.Now.ToString();
        }
    } 

here you can get today date  then after get this date on all textbox


protected void txt1_TextChanged(object sender, EventArgs e)
    {   
              If txt1.Text = "" Then

                    If txt1.Text <> "" Then
                        txt2.Text = txt1.Text
                        txt3.Text = txt1.Text
                        txt4.Text = txt1.Text
                        txt5.Text = txt1.Text
                        txt6.Text = txt1.Text
                    End If
                End If

 }
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
TextBox1.Text=DateTime.Now.ToString();
TextBox1_TextChanged(TextBox1.Text,null);
}
其他的
{
TextBox1_TextChanged(TextBox1.Text,null);
}
}
受保护的void TextBox1\u TextChanged(对象发送方,事件参数e)
{
TextBox2.Text=TextBox1.Text;
}
无标题页

添加此代码是可行的

我使用jquery获得您所需的解决方案。请尝试此操作

在Html中的head元素中添加以下代码

<head runat="server">

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


     <script>
         $(function () {
             $("#txt1").datepicker();
             $("#txt2").datepicker();
             $("#txt3").datepicker();
             $("#txt4").datepicker();
             $("#txt5").datepicker();
             $("#txt6").datepicker();
         });
         $(document).ready(function () {
             ShowTime();
             $("#txt1").change(function () {
                 $("#txt2").val($("#txt1").val());
                 $("#txt3").val($("#txt1").val());
                 $("#txt4").val($("#txt1").val());
                 $("#txt5").val($("#txt1").val());
                 $("#txt6").val($("#txt1").val());
             });
         });
         function ShowTime() {
             var dt = new Date();
             $("#txt1").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt2").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt3").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt4").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt5").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt6").val($.datepicker.formatDate('mm/dd/yy', new Date()));

         }

</script>
</head>

$(函数(){
$(“#txt1”).datepicker();
$(“#txt2”).datepicker();
$(“#txt3”).datepicker();
$(“#txt4”).datepicker();
$(“#txt5”).datepicker();
$(“#txt6”).datepicker();
});
$(文档).ready(函数(){
ShowTime();
$(“#txt1”).change(函数(){
$(“#txt2”).val($(“#txt1”).val());
$(“#txt3”).val($(“#txt1”).val());
$(“#txt4”).val($(“#txt1”).val());
$(“#txt5”).val($(“#txt1”).val());
$(“#txt6”).val($(“#txt1”).val());
});
});
函数ShowTime(){
var dt=新日期();
$(“#txt1”).val($.datepicker.formatDate('mm/dd/yy',new Date());
$(“#txt2”).val($.datepicker.formatDate('mm/dd/yy',new Date());
$(“#txt3”).val($.datepicker.formatDate('mm/dd/yy',new Date());
$(“#txt4”).val($.datepicker.formatDate('mm/dd/yy',new Date());
$(“#txt5”).val($.datepicker.formatDate('mm/dd/yy',new Date());
$(“#txt6”).val($.datepicker.formatDate('mm/dd/yy',new Date());
}
注意:
如果您想更改我的代码,请使用诸如“mm/dd/yy”之类的日期格式。

r您使用asp.net控件或日期时间选择器的jquery?@ajay:我使用asp.net控件。@Shuttler检查其他新答案。。。。这是工作……@Shuttler检查一下。。。。。。。。。如果你得到一个解决方案,然后给马克作为答案…@pratik先生,我需要一个VB代码和更多,我没有使用任何AJAX控件感谢你的回答。正如我上面提到的,我已经做了今天的日期。我需要知道,当我在txt1中更改日期时,它必须反映在所有其他文本框中。希望我清楚我想要什么。是的,您可以在这个事件中更改日期时获取日期
txt1\u TextChanged
u可以在textbox1的
txt1\u TextChanged
事件中添加您的条件,当textbox更改此事件时,您可以在所有文本框中获取日期需要。我也试过了,但是只有当按钮被点击时,它才会改变。我不想这样。如果我没有任何按钮,它会如何改变?我已尝试过此代码私有子txt1_TextChanged(ByVal sender作为对象,ByVal e作为System.EventArgs)处理txt1.TextChanged txt2.Text=“”如果txt_photodate.Text“”然后,如果txt_photodate.Text Today,那么txt2.Text=txt1.Text End If End If End If End If End Subon此更改事件中,当您关注其他文本框并设置AutoPostBack=“true”时,您不需要使用buton
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextBox1.Text = DateTime.Now.ToString();
            TextBox1_TextChanged(TextBox1.Text, null);
        }
        else
        {
            TextBox1_TextChanged(TextBox1.Text, null);
        }
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        TextBox2.Text = TextBox1.Text;
    }

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>

    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
        EnablePartialRendering="true">
    </asp:ScriptManager>
        <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server" 
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1"
            Mask="99/99/9999" MaskType="Date" />
        <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"
            Format="dd/MM/yyyy">
        </cc1:CalendarExtender>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="TextBox2"
            Mask="99/99/9999" MaskType="Date" />
        <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox2"
            Format="dd/MM/yyyy">
        </cc1:CalendarExtender>
    </div>
    </form>
</body>
</html>
<head runat="server">

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


     <script>
         $(function () {
             $("#txt1").datepicker();
             $("#txt2").datepicker();
             $("#txt3").datepicker();
             $("#txt4").datepicker();
             $("#txt5").datepicker();
             $("#txt6").datepicker();
         });
         $(document).ready(function () {
             ShowTime();
             $("#txt1").change(function () {
                 $("#txt2").val($("#txt1").val());
                 $("#txt3").val($("#txt1").val());
                 $("#txt4").val($("#txt1").val());
                 $("#txt5").val($("#txt1").val());
                 $("#txt6").val($("#txt1").val());
             });
         });
         function ShowTime() {
             var dt = new Date();
             $("#txt1").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt2").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt3").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt4").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt5").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt6").val($.datepicker.formatDate('mm/dd/yy', new Date()));

         }

</script>
</head>