在我的Django项目中,我试图使用jQuery添加日期选择器。当我在浏览器中加载页面时,控制台会给我一个错误:
未捕获的TypeError:$(...)。datepicker不是函数
我在一个简单的HTML页面中尝试了相同的AJAX代码,并且在那里工作正常。为什么此datepicker()
函数无法从源位置加载到Django中?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
<p>Date: <input type="text" id="datepicker"></p>
{% block contents %} {% endblock %}
</body>
</html>