[英]Bootstrap-datepicker how to put date into input field
Im wondering how I can put the selected date with bootstrap-datepicker into an input field when the calender is embedded. 我想知道嵌入日历时如何将带有bootstrap-datepicker的选定日期放入输入字段中。 Somehow I can't get it to work. 不知何故我无法正常工作。
Right now I have this: 现在我有这个:
<script>
$('#sandbox-container div').datepicker({
weekStart: 1,
startDate: "-",
maxViewMode: 0,
clearBtn: true,
language: "nl",
orientation: "top auto",
daysOfWeekDisabled: "0,1,2,3,4",
calendarWeeks: true,
todayHighlight: true
});
</script>
And in the template I have: 在模板中,我有:
<div id="sandbox-container">
<div id="datepicker"></div>
</div>
However when i'm trying to do something like: 但是,当我试图做类似的事情:
<script>
$('#sandbox-container input').datepicker({
weekStart: 1,
startDate: "-",
maxViewMode: 0,
clearBtn: true,
language: "nl",
orientation: "top auto",
daysOfWeekDisabled: "0,1,2,3,4",
calendarWeeks: true,
todayHighlight: true
});
</script>
and: 和:
<div id="sandbox-container">
<input type=text id="datepicker">
</div>
Its is only showing a input field. 它仅显示一个输入字段。 What am I doing wrong? 我究竟做错了什么?
Two things: 两件事情:
1) Presumably you know that the datepicker comes with JQueryUI. 1)大概您知道datepicker随JQueryUI一起提供。 However, if you didn't know this then you'll need to include that under JQuery first. 但是,如果您不知道这一点,则需要首先将其包括在JQuery中。 For example: 例如:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
2) Secondly, it looks like your selector isn't written properly. 2)其次,看起来您的选择器编写不正确。 This should work: 这应该工作:
<script>
$(function() {
$("#sandbox-container input").datepicker({
weekStart: 1,
startDate: "-",
maxViewMode: 0,
clearBtn: true,
language: "nl",
orientation: "top auto",
daysOfWeekDisabled: "0,1,2,3,4",
calendarWeeks: true,
todayHighlight: true
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.