[英]Why won't jQuery UI Datepicker work after using jQuery to change the value of the input box?
[英]jQuery Datepicker won't change value of input
我使用jquery中的datepicker函数。 现在我已经集成了一个内联日历。 应该可以在显示的月份中点击一天,然后提交表单或更改网址。 我需要将新日期添加到网址,以便我可以跳转到此日期。
但我的代码不会改变输入的值 - 我不知道为什么。
这是我的代码:
在头部区域:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="templates/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="templates/js/bootstrap-datepicker.de.js"></script>
HTML:
<form method="get" action="index.php">
<div class="form-group">
<div class="minicalendar"></div>
<input class="form-control" type="text" name="submitDate" id="submitDate" />
</div>
</form>
JS:
$('.minicalendar').datepicker({
format: "dd.mm.yyyy",
todayBtn: true,
language: "de",
calendarWeeks: true,
todayHighlight: true,
onSelect: function(dateText, inst) {
$('#submitDate').val(dateText);
}
});
你知道为什么吗? 我现在正在寻找一段时间,但我无法找到有效的解决方案......
谢谢。
您将datepicker绑定到div
而不是input
。
<input id="datepicker" />
$('#datepicker').datepicker({
//...
});
您也无需使用onSelect
事件更改输入文本。 小部件将自动执行thix。
$('#submitDate').datepicker({
format: "dd.mm.yyyy",
todayBtn: true,
language: "de",
calendarWeeks: true,
todayHighlight: true,
onSelect: function(dateText, inst) {
$('#submitDate').val(dateText);
}
});
用这个。 Datepicker不会绑定到<div>
它必须是<input>
元素。 有关更多示例,请查看此链接 。
以下是JQuery UI DatePicker的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
输入id必须与在JQuery中选择的元素相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.