Jquery日期选择器,如果是今天的日期,则执行一个对话框

发布于 2024-12-27 07:28:16 字数 607 浏览 2 评论 0原文

我想设置此 jquery 日期选择器,以便在所选日期是今天的日期时引发警报/对话框。我正在使用 smarty,这就是你看到的日期函数。但是,当我输入今天的日期时,脚本仍然不会返回代表今天的对话框。这是脚本:

$("#sanctionDateStart").datepicker({
    altField: "#sanctionDateStart_hidden", 
    altFormat: "yy-mm-dd", 
    minDate: new Date()
}).datepicker("setDate", "{$data.sanctionDateStart}").change(function () {
    $('#sanctionDateEnd').datepicker('option', 'minDate',
    $(this).datepicker('getDate'));
    if ($(this).datepicker('getDate') == '{date("m/d/Y", $smarty.now)}'){
        alert ('Todays Date');  
    }
    else {
        alert ('Not Todays Date');
    }
});

I am wanting to set this jquery date picker to throw an alert / dialog if the date selected is todays date. I am using smarty, thats the date function you see. However when I input todays date, the script will still not return the dialog that represents today. Here is the script:

$("#sanctionDateStart").datepicker({
    altField: "#sanctionDateStart_hidden", 
    altFormat: "yy-mm-dd", 
    minDate: new Date()
}).datepicker("setDate", "{$data.sanctionDateStart}").change(function () {
    $('#sanctionDateEnd').datepicker('option', 'minDate',
    $(this).datepicker('getDate'));
    if ($(this).datepicker('getDate') == '{date("m/d/Y", $smarty.now)}'){
        alert ('Todays Date');  
    }
    else {
        alert ('Not Todays Date');
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长亭外,古道边 2025-01-03 07:28:16

使用日期选择器 onSelect 而不是 .change

 $('selector').datepicker( {
    onSelect: function(date) {
        //Do your thing here
        //date hold selected date
    }
 });

Use Datepicker onSelect instead of .change

 $('selector').datepicker( {
    onSelect: function(date) {
        //Do your thing here
        //date hold selected date
    }
 });
千笙结 2025-01-03 07:28:16

日期选择器返回一个 Date 对象,该对象不能等于字符串。您需要将 Smarty 中的字符串转换为 JS Date。请参阅日期文档了解如何这样做。

The date picker returns a Date object, which can't be equal to a string. You need to convert the string from Smarty into a JS Date. See the Date documentation to see how to do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文