我尝试删除和添加内容,但下拉列表仍然不会丢失。我不确定问题是什么。我添加了较少的文件,包括下拉列表,但仍然没有改变。文本框工作正常。这是代码的样子
<html>
<head><link rel="stylesheet" type="text/css" media="screen"
href="css/datepicker3.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet/less" href="less/dropdowns.less">
<link rel="stylesheet/less" href="less/sprites.less">
</head>
<body>
<div class="input-group date" data-date-format="dd-mm-yyyy">
<input type="text" class="form-control" name="date"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
<script type="text/javascript">
$('.input-group.date').datepicker({
changeMonth: true;
changeYear: true;
});
</script>
<script type="text/javascript"
src="js/jquery-1.11.2.min.js">
</script>
</script>
<script type="text/javascript"
src="js/bootstrap.js">
</script>
<script type="text/javascript"
src="js/bootstrap.min.js">
</script>
<script type="text/javascript"
src="js/bootstrap-datepicker.js">
</script>
<script type="text/javascript"
src="js/bootstrap-datepicker.en-GB.js">
</script>
</body>
</html>
答案 0 :(得分:1)
在jquery和bootstrap.js加载之前,您正在执行自定义javascript方法。只有在方法执行之前加载库类时,您的自定义方法才有效。所以,您的代码必须如下所示:
<html>
<head><link rel="stylesheet" type="text/css" media="screen"
href="css/datepicker3.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet/less" href="less/dropdowns.less">
<link rel="stylesheet/less" href="less/sprites.less">
</head>
<body>
<div class="input-group date" data-date-format="dd-mm-yyyy">
<input type="text" class="form-control" name="date"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
<script type="text/javascript"
src="js/jquery-1.11.2.min.js">
</script>
</script>
<script type="text/javascript"
src="js/bootstrap.min.js">
</script>
<script type="text/javascript"
src="js/bootstrap-datepicker.js">
</script>
<script type="text/javascript"
src="js/bootstrap-datepicker.en-GB.js">
</script>
<script type="text/javascript">
$('document').ready(function(){
$('.input-group.date').datepicker({
changeMonth: true,
changeYear: true,
});
});
</script>
</body>
</html>
$('.input-group.date').datepicker({changeMonth: true,
changeYear: true});
&#13;
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.1/css/datepicker.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.1/css/datepicker.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="input-group date" data-date-format="dd-mm-yyyy">
<input type="text" class="form-control" name="date"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.1/js/bootstrap-datepicker.min.js"></script>
</body>
</html>
&#13;
也没有&#34;;&#34;但&#34;,&#34;在datepicker选项中,
正如@ Sachi Tekina
所说,不需要加载bootstrap两次。
答案 1 :(得分:0)
在导入js文件之前,您正在调用datepicker函数。 同时删除下面的行,因为您已经调用了缩小版本。
<script type="text/javascript" src="js/bootstrap.js">
</script>
</script>
<script type="text/javascript" src="js/bootstrap.js"></script>
标记
试试这样:
<html>
<head><link rel="stylesheet" type="text/css" media="screen"
href="css/datepicker3.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet/less" href="less/dropdowns.less">
<link rel="stylesheet/less" href="less/sprites.less">
</head>
<body>
<div class="input-group date" data-date-format="dd-mm-yyyy">
<input type="text" class="form-control" name="date"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
<script type="text/javascript" src="js/jquery-1.11.2.min.js">
</script>
<script type="text/javascript" src="js/bootstrap.min.js">
</script>
<script type="text/javascript" src="js/bootstrap-datepicker.js">
</script>
<script type="text/javascript" src="js/bootstrap-datepicker.en-GB.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.input-group.date').datepicker({
changeMonth: true;
changeYear: true;
});
});
</script>
</body>
</html>
答案 2 :(得分:0)
尝试
$('.date').datepicker({
changeMonth: true;
changeYear: true;
});