如何在日期选择器中将静态日期设置为开始日期?
How to set a static date to the from date in the datepicker?
我正在开发一个日期计算器,其中包含两个文本框,其中一个文本框具有静态日期,例如(2016 年 7 月 1 日),并且日期应更改为当前日期。
截止日期的这段代码工作正常,但静态日期没有自动填充到文本字段中。
此处应填写开始日期。现在,来自文本框的 class 名称为 'textbox',我已经开始研究这个,但它给了我一些错误,但它没有被填充。
在执行此操作之前,我已经包含了 jQuery 以供使用。
$('.textbox').datepicker("setDate", new Date(2008,9,03) );
它给了我这样的错误:
attendance.js:25 Uncaught TypeError: $(...).datepicker is not a function(…)(anonymous function) @ attendance.js:25
我应该这样。谁能帮帮我?
这样使用
$('.textbox').datepicker({"setDate":new Date(2008,9,03)} );
您忘记包含 jQuery UI 库:
$( "#datepickerFrom" ).datepicker({
dateFormat: "dd-M-yy"
});
$( "#datepickerTo" ).datepicker({
dateFormat: "dd-M-yy"
});
$( "#datepickerTo" ).datepicker("setDate", new Date());
$('.textbox').datepicker("setDate", new Date(2016, 6, 1));
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<p>From: <input type="text" class="textbox" id="datepickerFrom"></p>
<p>From: <input type="text" id="datepickerTo"></p>
我正在开发一个日期计算器,其中包含两个文本框,其中一个文本框具有静态日期,例如(2016 年 7 月 1 日),并且日期应更改为当前日期。
截止日期的这段代码工作正常,但静态日期没有自动填充到文本字段中。
此处应填写开始日期。现在,来自文本框的 class 名称为 'textbox',我已经开始研究这个,但它给了我一些错误,但它没有被填充。
在执行此操作之前,我已经包含了 jQuery 以供使用。
$('.textbox').datepicker("setDate", new Date(2008,9,03) );
它给了我这样的错误:
attendance.js:25 Uncaught TypeError: $(...).datepicker is not a function(…)(anonymous function) @ attendance.js:25
我应该这样。谁能帮帮我?
这样使用
$('.textbox').datepicker({"setDate":new Date(2008,9,03)} );
您忘记包含 jQuery UI 库:
$( "#datepickerFrom" ).datepicker({
dateFormat: "dd-M-yy"
});
$( "#datepickerTo" ).datepicker({
dateFormat: "dd-M-yy"
});
$( "#datepickerTo" ).datepicker("setDate", new Date());
$('.textbox').datepicker("setDate", new Date(2016, 6, 1));
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<p>From: <input type="text" class="textbox" id="datepickerFrom"></p>
<p>From: <input type="text" id="datepickerTo"></p>