我正在使用jQuery datepicker将日期作为参数附加到url的末尾。一切正常,但我想按以下格式设置日期:
$('#datepicker')。datepicker({inline:true,dateFormat:'ddmmyy'});
当我在“ onSelect”下面的代码的第7行尝试这种操作时,仅填充输入字段是行不通的,很明显我得到了语法或方括号或某些错误?
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></scrip>
<script>
$(document).ready(function() {
$('#datepicker').datepicker({ <!-- The issue is here -->
onSelect : function (dateText, inst) {
var pathname = window.location.pathname;
var datepickedup = $("input#datepicker").val();
window.location.href = (pathname + "?startdate=" + datepickedup);
('#myform').submit();
}
});
});
</script>
</head>
<body>
<form id='myform' method="post">
<input type="text" id="datepicker"/>
</form>
</body>
</html>
答案 0 :(得分:0)
您应该在方括号内添加所有选项。
$(document).ready(function () {
$('#datepicker').datepicker({
inline: true,
dateFormat: 'ddmmyy',
onSelect: function (dateText, inst) {
var pathname = window.location.pathname;
var datepickedup = $("input#datepicker").val();
window.location.href = (pathname + "?startdate=" + datepickedup);
('#myform').submit();
}
});
});