的src:
<script src="Scripts/jquery.min.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/bootstrap-datepicker.min.js"></script>
<script type="text/javascript">
脚本:
$(function () {
$("#datetimepicker1").datepicker({ dateFormat: "yy-mm-dd" });
$("#datetimepicker1").on("change", function () {
var selected = $(this).val();
$("<%=txtDate.ClientID %>").val(selected)
});
});
</script>
设计师:
<div class="form-group">
<label for="txtDate" class="control-label col-sm-2 col-md-2 col-lg-2"> preferred date </label>
<div class="col-sm-4 col-md-4 col-lg-4 col-xs-10">
<asp:TextBox ID="txtDate" runat="server" CssClass="form-control datepick"></asp:TextBox>
</div>
<div class="col-sm-2 col-md-2 col-lg-2 col-xs-2">
<button type="button" id="datetimepicker1" class="common-button2"><span aria-hidden="true" class="glyphicon glyphicon-calendar"></span></button>
</div>
</div>
好的,问题是,日历弹出,但文本框不会获得所选日期,所有脚本都包含在内并且没有错误。请帮助谢谢!
编辑:使用&lt;%= txtDate.ClientID%&gt;因为我的页面有一个母版页。
答案 0 :(得分:0)
$("<%=txtDate.ClientID %>").val(selected)
不是有效的jquery选择器
你想要
$("#txtDate").val(selected)
答案 1 :(得分:0)
如果您没有使用任何母版页,那么只需编写
$("#txtDate").val(selected);
否则
$("#<%=txtDate.ClientID %>").val(selected);
'#'非常重要,因为它表示这是一个ID。
答案 2 :(得分:0)
你使datepicker
太难用了。
这是简单的解决方案
<p>
Date:
<input type="text" id="datepicker"></p>
JS: -
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
请参阅Working demo
<强>更新强>
$(function () {
$("#Id generated by inspecting element from browser").datepicker();
});
答案 3 :(得分:0)
jquery datepicker返回 onSelect 事件而不是onChange上的选定值。试试这个
<script>
$(function () {
$("#datetimepicker1").datepicker({ dateFormat: "yy-mm-dd" }, onSelect: function(dateText) {
$("<%=txtDate.ClientID %>").val(dateText)
});
});
</script>