javascript Bootstrap 3 Datepicker 不显示日历
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30782006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap 3 Datepicker doesn't show calendar
提问by BaddieProgrammer
I've included the following in my page:
我在我的页面中包含了以下内容:
In the <head>
在里面 <head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified jQuery Core -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Bottom of <body>
底部 <body>
<!-- Moments.js minified CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<!-- Bootstrap datepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.min.js"></script>
Then I used jQuery to turn my form's input field into the datepicker:
然后我使用 jQuery 将表单的输入字段转换为日期选择器:
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
});
</script>
The input field got styled like a date picker(field with a calendar icon at the end), but when I click anywhere on that field or the icon the calendar doesn't show up.
输入字段的样式类似于日期选择器(字段末尾带有日历图标),但是当我单击该字段或图标上的任何位置时,日历不会显示。
I've re-read the Installationtutorial but I don't see anything missing.
我已经重新阅读了安装教程,但我没有看到任何遗漏。
回答by Awlad Liton
Replace
代替
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.min.js"></script>
By
经过
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.14.30/js/bootstrap-datetimepicker.min.js"></script>
You should get TypeError: $(...).datetimepicker is not a function
in the browser console.
您应该进入TypeError: $(...).datetimepicker is not a function
浏览器控制台。
Because you include only datepicker not datetimepicker.
因为您只包含 datepicker 而不是 datetimepicker。
回答by elreeda
Add datetimepicker1To <input type='text' class="form-control" id="datetimepicker1" />
将datetimepicker1添加到 <input type='text' class="form-control" id="datetimepicker1" />
and $('#datetimepicker1').datepicker();
not $('#datetimepicker1').datetimepicker();
而$('#datetimepicker1').datepicker();
不是$('#datetimepicker1').datetimepicker();
Wokring here :
在这里工作:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">-->
</head>
<body>
<div class="form-group">
<div class='input-group date' >
<input type='text' class="form-control" id="datetimepicker1" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<!-- Latest compiled and minified jQuery Core -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datepicker();
});
</script>
</body>
</html>
回答by adelowo
if you opened the browser console,you would have seen an exception error in the console,like bootstrap JS requires jquery
or so
如果您打开浏览器控制台,您会在控制台中看到异常错误,例如bootstrap JS requires jquery
左右
<!-- Latest compiled and minified jQuery Core -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"> </script>
this should work
这应该有效