jQuery 日期选择器未在文本框中设置 maxDate
我在代码中使用 jquery.ui.datepicker 。我已将 maxDate
设置为 +0
即当前日期。因此,在日历控件中,未来日期被禁用,但用户仍然可以在文本框中键入未来日期。如何限制用户仅输入小于 maxDate 的日期,如果用户输入任何未来日期,我想在模糊的文本框中显示当前日期。
$txtDate.datepicker({
dateFormat: MyPage.config.dateFormat,
onClose: function (dateText, inst) {
try {
$.datepicker.parseDate(MyPage.config.dateFormat, dateText);
} catch (e) {
$txtDate.val('');
};
},
maxDate: '+0'
});
$txtDate.datepicker('setDate', new Date()).blur(function () {
try {
if ($txtDate.val() == '') {
$txtDate.datepicker('setDate', new Date());
}
}
catch (ex) {
var MyEx = MyWeb.Exception(ex);
MyEx.AddData("Method", "$txtDate.datepicker('setDate', new Date()).blur");
$.errorhandler("HandleError", MyEx);
}
});
I am using jquery.ui.datepicker in my code. I have set maxDate
to +0
i.e. current date. So in the calendar control the future dates are disabled but user is still able to key in the future date in the textbox. How to restrict the user to enter only the dates less than maxDate and if user enter any future date I want to show the current date in the textbox on blur.
$txtDate.datepicker({
dateFormat: MyPage.config.dateFormat,
onClose: function (dateText, inst) {
try {
$.datepicker.parseDate(MyPage.config.dateFormat, dateText);
} catch (e) {
$txtDate.val('');
};
},
maxDate: '+0'
});
$txtDate.datepicker('setDate', new Date()).blur(function () {
try {
if ($txtDate.val() == '') {
$txtDate.datepicker('setDate', new Date());
}
}
catch (ex) {
var MyEx = MyWeb.Exception(ex);
MyEx.AddData("Method", "$txtDate.datepicker('setDate', new Date()).blur");
$.errorhandler("HandleError", MyEx);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将其放入您的输入 html 元素中:
并使用服务器端技术将值默认为今天的日期:
Just put this in your input html element:
And use a serverside technology to default the value to today's date: