我有一個代碼來生成一個正常的日期時間選擇器,但它給我這個錯誤Uncaught TypeError: jQuery(...).datetimepicker is not a function
任何人都可以幫助我,我想這是因為鏈接和引導程式的安排,但我沒有清晰的畫面。
下面是我的代碼
<html>
<head>
<link rel="stylesheet" href="jquery.datetimepicker.css">
<script src="jquery-1.8.2.min.js"></script>
<!-- <script src="jquery-ui.js"></script> -->
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script src="jquery.datetimepicker.js"></script>
<script src="jquery.validate.min.js"></script>
<link rel="stylesheet" href="fonts/icomoon/style.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script>
$(document).ready(function() {
jQuery('#datevalue').datetimepicker();
jQuery('#completed').datetimepicker();
});
</script>
</head>
<body>
<form action="#" method="post">
<div id="AlignMainDiv">
<div >
<label for="date">Date</label>
<input type="text" id="datevalue">
</div>
<div >
<label for="username">Completed Date and Time</label>
<input type="text" id="completed">
</div>
</div>
</form>
</body>
</html>
uj5u.com熱心網友回復:
按 F11,打開 Chrome 除錯,轉到 Network > JS 選項卡并檢查是否有任何包含的 js 庫回傳 404 狀態。也許您拼錯了腳本名稱或 URL 路徑。
您還可以嘗試直接從 CDN 包含庫:
<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.13.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script>
$( function() {
$('#datevalue').datetimepicker();
$('#completed').datetimepicker();
} );
</script>
</head>
uj5u.com熱心網友回復:
我不知道您的 datetimepicker 庫是否正在加載。
您可以使用以下 CDN。
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.min.js"></script>
以下代碼將加載今天的日期并在輸入點擊時顯示日期選擇器
<script>
$(document).on("click", "#datevalue" , function() {
$(this).datetimepicker({
timepicker:false, format:"d-m-Y","setDate": new Date(),
}).focus();
});
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/455103.html
上一篇:基于影像區域的jQuery函式
