【发布时间】:2014-12-05 15:06:25
【问题描述】:
我正在尝试使用我从 PHP 传递到 html 的变量在 datepicker 中设置默认日期。这是我的控制文件和表单的简化版本:
控制文件:
<?php
function render($template, $values = []) {
// extract variables into local scope
extract($values);
// render template
require("$template");
}
$default_date = date("m/d/Y") ;
$default_date = strtotime($default_date);
$default_date = $default_date + 604800;
$default_date = date("Y,m-1,d",$default_date);
render("index_month2_form.php",['default_date'=> $default_date]);
?>
这是表格:
<!doctype html>
<html lang="en">
<head>
<?php print "$default_date"; ?>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="jqueryui/css/swanky-purse/jquery-ui-1.10.4.custom.css">
<script src="/jqueryui/jquery-1.11.1.min.js"> </script>
<script src="jqueryui/js/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
$(function() {
$("#mydate").datepicker ({
onSelect: function(dateText, inst) {
var dateAsString = dateText;
var date = $('#mydate').val();
}
})
//.datepicker("setDate",new Date());
.datepicker("setDate",new Date(2014,10-1,17));
});
</script>
</head>
<body>
<p>Date: <input type="text" id="mydate"></p>
</body>
</html>
如果我使用 setDate 的注释行,我会得到当前日期。如果我使用我拥有的线路,我会提前 7 天得到日期。当我在表单顶部打印 $default_date 时,我得到 2014,10-1,17 但我无法将其传递到脚本中。其他人建议使用
【问题讨论】:
-
其他人建议使用
-
HTML 表单的 PHP 代码中有一个额外的右括号“)”。我为你修好了。
-
谢谢,但你能告诉我额外的“)”所在的确切行吗?我在我的代码中找不到它??
-
没关系,这是我的错。没有额外的“)”。很抱歉造成混乱。
标签: javascript php jquery datepicker