jQuery Datepicker无法呈现

时间:2018-10-21 07:45:18

标签: javascript jquery html

我遇到了一个问题,即日期选择器控件无法在我的HTML页面上呈现。在控制台上查看错误时,我看到:SCRIPT438: SCRIPT438: Object doesn't support property or method 'datepicker'

我的代码如下:

    $( function() {
    $( "#datepicker" ).datepicker();
    } );
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<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>

<p>Date: <input type="text" id="datepicker"></p>

1 个答案:

答案 0 :(得分:0)

您只需将脚本移动到结束正文标签之前 </body>,请尝试以下操作:

<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <!-- fixed the url -->
<link rel="stylesheet" href="/resources/demos/style.css">
</head>
<body>

<!-- YOUR CODE START HERE -->
<p>Date: <input type="text" id="datepicker"></p>
<!-- YOUR CODE END HERE -->

<!-- YOUR SCRIPTS START HERE -->
<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>
<script>
$(document).ready(function() {
    $( "#datepicker" ).datepicker();
});
</script>
<!-- YOUR SCRIPTS END HERE -->

</body>
</html>