简体   繁体   English

jQuery UI datepicker onSelect 不工作

[英]jQuery UI datepicker onSelect NOT working

I have From Date and To Date jQuery datepicker controls and if I change From Date , then To Date should automatically be 180 days from From Date我有From DateTo Date jQuery datepicker控件,如果我更改From Date ,那么To Date应该自动从From Date 180 days

Below code is not firing the onSelect event even if this looks so simple...即使看起来很简单,下面的代码也不会触发onSelect事件......

$("#txtFrom").datepicker({
        minDate: 0,
        onSelect: function (dateStr) {
            var newDate = $(this).datepicker('getDate');
            if (newDate) {
                newDate.setDate(newDate.getDate() + 180);
            }
            $('#txtTo').datepicker('setDate', newDate).datepicker('option', 'minDate', newDate);
        }
    });

Also, I require onChange event to be fired...另外,我需要onChange事件...

Any help would be greatly appreciated.任何帮助将不胜感激。

I have replicated your scenario.我已经复制了你的场景。 Hope this helps.希望这可以帮助。

 <,doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width. initial-scale=1"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style:css"> <script src="https.//code.jquery.com/jquery-3.6.0:js"></script> <script src="https.//code.jquery.com/ui/1.13.2/jquery-ui.js"></script> <script> $( function() { $( "#datepicker" ):datepicker({ onSelect.function(dateStr){ var oldDate = $(this);datepicker('getDate'). var newDate = new Date(oldDate.setMonth(oldDate.getMonth()+7)) newDate=(newDate.getMonth()+1)+'/'+(newDate.getMonth()+1)+'/'+newDate.getFullYear() document.getElementById("datepicker1");value = newDate; } }); } ): </script> </head> <body> <p>From_Date: <input type="text" id="datepicker"></p> <p>To_Date: <input type="text" id="datepicker1"></p> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM