datepicker JQuery 验证和格式
我在 Jquery 中使用以下日期选择器以 dd/mm/yy 格式格式化日期显示,而且我希望用户不要选择未来的日期。一次只有一件事在工作。
<script type="text/javascript" language ="javascript" >
$(function () {
var date = new Date();
var currentDate = date.getDate();
var currentMonth = date.getMonth();
var currentYear = date.getFullYear();
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
$(".datepicker").datepicker({ maxDate: new Date(currentYear, currentMonth, currentDate) });
});
</script>
如何使日期格式和禁用未来日期同时工作。我缺少一点,我不知道如何将这两个验证或要求结合在一起。
请问有什么答案吗?
谢谢。
I am using the following for datepicker in Jquery to format the date display in dd/mm/yy format and also I want the user not to select future date.Only one thing is working at a time.
<script type="text/javascript" language ="javascript" >
$(function () {
var date = new Date();
var currentDate = date.getDate();
var currentMonth = date.getMonth();
var currentYear = date.getFullYear();
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
$(".datepicker").datepicker({ maxDate: new Date(currentYear, currentMonth, currentDate) });
});
</script>
How do make, both the dateformat and disable the future dates to work simultaneously. I am missing single bit, I don't know how to club this two validations or requirements togather.
Any answers Please?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对带有雇用日期的代码有类似的要求。我是这样做的:
I had a similar requirement for my code with a hire date. Here's how I did it:
用户仍然可以手动输入未来的日期并围绕您的日期选择器进行操作。我们在生产系统上遇到了这个问题。
如果您想使用验证插件另外验证日期,请尝试以下操作:
HTML:
The user can still enter a future date manually and weasel around your date picker. We had this problem on a production system.
If you want to additionally validate the date using the validation plugin, try this:
HTML: