javascript 将昨天设置为 Jquery 日期选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16990260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:41:58  来源:igfitidea点击:

Setting Yesterday to Jquery datepicker

javascriptjquerydatedatepicker

提问by Shamim Hafiz

I am trying to set yesterdays day to a Jquerydatapickeras follows:

我试图将昨天的一天设置Jquerydatapicker为如下:

$(".datepicker").datepicker("setDate", (new Date().getDate() - 1) );

However, I am always getting todays date. The code is located in $(document).readyand it does get excuted, cause if I comment out the line abobve, no value shows up.

但是,我总是收到今天的日期。该代码位于$(document).ready并且它确实被执行了,因为如果我注释掉上面的行,则不会显示任何值。

Could anyone point out what I am doing wrong.

谁能指出我做错了什么。

回答by Eric Wich

$( ".datepicker" ).datepicker({ defaultDate: -1 });

That ought to do the trick, courtesy of http://docs.jquery.com/UI/Datepicker#option-defaultDate

这应该可以解决问题,由http://docs.jquery.com/UI/Datepicker#option-defaultDate 提供

回答by Hossain Misho

It's worked for me ...

它对我有用...

$(".datepicker")..datepicker("setDate", "-1d");

link bootstrap datepicker

链接引导日期选择器