HTML:
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Expected Date</label>
<div class="input-group date form_datetime form_datetime bs-datetime">
<input id="access_from" name="access_from" size="16" class="form-control" id="from" type="date">
<span class="input-group-addon">
<button id="click" class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
jQuery代码:
<script type="text/javascript">
$(document).ready(function(){
$("#click").click(function() {
$("#access_from").datepicker("show");
});
});
</script>
从此代码中,我的日期选择器未打开。我做错了什么?
答案 0 :(得分:4)
您在输入元素中添加id
属性两次。
删除id="from"
和type="date"(具有特定日期格式)并使用以下
<input id="access_from" name="access_from" size="16" class="form-control" />
$(document).ready(function() {
$("#click").click(function() {
$("#access_from").datepicker("show");
});
});
&#13;
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.0/js/bootstrap-datepicker.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.0/css/bootstrap-datepicker.css" rel="stylesheet" />
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Expected Date</label>
<div class="input-group date form_datetime form_datetime bs-datetime">
<input id="access_from" name="access_from" size="16" class="form-control"/>
<span class="input-group-addon">
<button id="click" class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
&#13;