一旦选择了日期值,Bootstrap日期选择器将引发错误?

时间:2019-07-08 20:13:23

标签: twitter-bootstrap twitter-bootstrap-3 bootstrap-datepicker

我在项目中实现了引导日期选择器。这是我的代码示例:

$( document ).ready(function() {
    	$('.datepicker').datepicker({});
	});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>



<div class="container">
  <div class="row">
			<div class="col-xs-12">
				<div class="input-group date">
				    <input type="text" class="form-control datepicker" name="beg_dt" id="beg_dt" value="" size="10">
				    <div class="input-group-addon">
				        <span class="glyphicon glyphicon-th"></span>
				    </div>
				</div>
			</div>
		</div>
</div>

我不确定为什么日期选择器不起作用。我还需要设置输入字段的宽度。包含属性大小,但宽度不正确。宽度不等于10,而是遍及整个屏幕。如果有人对如何解决此问题有任何建议,请告诉我。

1 个答案:

答案 0 :(得分:1)

script标记中更改head文件的顺序。 jQuery-UI.js应该在bootstrap-datepicker.js之上。

这是同一个代码段

$(document).ready(function() {
  $('.datepicker').datepicker({});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-xs-6">
      <div class="input-group date">
        <input type="text" class="form-control datepicker" name="beg_dt" id="beg_dt" value="" size="10">
        <div class="input-group-addon">
          <span class="glyphicon glyphicon-th"></span>
        </div>
      </div>
    </div>
  </div>
</div>