如何在单击提交按钮时更改datepicker日期值 [英] How to change the datepicker date value on click of submit button

查看:99
本文介绍了如何在单击提交按钮时更改datepicker日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datepicker文本框和提交按钮.datepicker文本框默认显示今天的日期。单击提交按钮,我想使用Jquery在datepicker文本框中设置另一个日期。



似乎jquery函数工作正常。我可以更改date.But它会自动将日期更改为默认日期,该日期位于datepicker文本框中(初始值)。



请帮忙!



我尝试了什么:



JQuery

I have a datepicker textbox and submit button.The datepicker textbox defaultly shows the todays date.On click of submit button, I would like to set another date in datepicker textbox using Jquery.

It seems the jquery function working is fine.I am able to change the date.But It is automatically changing the date to default date which is in the datepicker textbox(inital value).

Please help!

What I have tried:

JQuery

function ValidateDate() {
    var sDate = $('#ScheduledDate').val();
    var sDateTo = $('#ScheduledDateTo').val();

   
    if (sDate == undefined || sDate == '') {
        alert("Please enter Scheduled Date.");
        return false;
    }
    else {
        
        var todaydate = $('#ScheduledDate').val();
        $('#ScheduledDateTo').datepicker('setDate', todaydate);
        return true;
    }

        
}





.cshtml



.cshtml






@Html。标签(预定日期:,新{@class =col-md-3 control-label})


@Html.Label("Scheduled Date:", new { @class = "col-md-3 control-label" })


@Html.TextBox(ScheduledDate,DateTime.Now.ToShortDateString(),new {@class =form-control datepicker})


@Html.TextBox("ScheduledDate", DateTime.Now.ToShortDateString(), new { @class = "form-control datepicker" })









@ Html.TextBox(ScheduledDateTo,DateTime.Now.ToShortDateString(),new { @class =form-control datepicker})


@Html.TextBox("ScheduledDateTo", DateTime.Now.ToShortDateString(), new { @class = "form-control datepicker" })






按日期搜索


Search by Date




推荐答案

( #ScheduledDat E)VAL();
var sDateTo =
('#ScheduledDate').val(); var sDateTo =


('#ScheduledDateTo')。val();


if(sDate == undefined || sDate ==''){
alert(请输入预定日期。);
返回false;
}
else {

var todaydate =
('#ScheduledDateTo').val(); if (sDate == undefined || sDate == '') { alert("Please enter Scheduled Date."); return false; } else { var todaydate =


('#ScheduledDate')。val();
('#ScheduledDate').val();


这篇关于如何在单击提交按钮时更改datepicker日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆