javascript - 无法读取未定义的属性 setdefaults
问题描述
我想要这个有什么问题?
发生了这个错误。
“无法读取未定义日期选择器的属性‘setdefaults’”
我不知道为什么这个错误enter code here
我确实搜索了这个错误,但每个人都说同样的答案“那个 jquery 不应该被声明两次。” 所以我找到了它被宣布两次的地方,但我没有找到
<html xmlns="http://www.w3.org/1999/xthml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<!--달력 이벤트-->
<script>
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd',
prevText: '이전 달',
nextText: '다음 달',
monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
dayNames: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesShort: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
showMonthAfterYear: true,
yearSuffix: '년',
showOn: 'both',
buttonImage: '../css/img/calendar.png',
buttonImageOnly: true
});
$(document).ready(function() {
$("#chk_dt").datepicker();
});
function equip_chg(){
var equip_cd_nm = $('#equip_no > option:selected').attr("value2");
$('#equip_cd_nm').val(equip_cd_nm);
}
</script>
<body>
<th>date</th>
<td><input type="text" class="calendar" id="chk_dt" name="chk_dt" value=""></td>
<script type="text/javascript">
$(document).ready(function() {
equip_chg()
var chk_dt = document.getElementById("chk_dt").value;
$('#inspector').val("<%=user_nm%>");
//console.log("");
//오늘날짜
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
// 한자리수일 경우 0을 채워준다.
if(month < 10){
month = "0" + month;
}
if(day < 10){
day = "0" + day;
}
var today = year + "-" + month + "-" + day
if(chk_dt == ""){
$('#chk_dt').val(today);
}else{
$('#chk_dt').val(chk_dt);
}
});
</script>
</body>
解决方案
您的标题中没有正确的脚本。datepicker 不是 jquery 库的一部分,而是 jquery ui 的一部分,并且不包括该 js 文件。我在下面的示例中进行了修复,但您仍然需要在您的网站中包含所有必需的图像以使其看起来不错
<html xmlns="http://www.w3.org/1999/xthml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<!--달력 이벤트-->
<script>
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd',
prevText: '이전 달',
nextText: '다음 달',
monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
dayNames: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesShort: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
showMonthAfterYear: true,
yearSuffix: '년',
showOn: 'both',
buttonImage: '../css/img/calendar.png',
buttonImageOnly: true
});
$(document).ready(function() {
$("#chk_dt").datepicker();
});
function equip_chg(){
var equip_cd_nm = $('#equip_no > option:selected').attr("value2");
$('#equip_cd_nm').val(equip_cd_nm);
}
</script>
<body>
<th>date</th>
<td><input type="text" class="calendar" id="chk_dt" name="chk_dt" value=""></td>
<script type="text/javascript">
$(document).ready(function() {
equip_chg()
var chk_dt = document.getElementById("chk_dt").value;
$('#inspector').val("<%=user_nm%>");
//console.log("");
//오늘날짜
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
// 한자리수일 경우 0을 채워준다.
if(month < 10){
month = "0" + month;
}
if(day < 10){
day = "0" + day;
}
var today = year + "-" + month + "-" + day
if(chk_dt == ""){
$('#chk_dt').val(today);
}else{
$('#chk_dt').val(chk_dt);
}
});
</script>
</body>
推荐阅读
- android - NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/internal/zzx
- php - WooCommerce 迷你购物车事件触发器
- python - 学习 Python 和 Scrapy
- node.js - HTTPError:在shopify中将结帐标记为已完成时的响应代码422(无法处理的实体)
- python - django 分页不适用于 django 过滤器
- php - 带有字段 concat 的语句 WHERE
- vb.net - 如何将图像从 Form1 分配到 Form2
- ruby - memcached:如何清除名称中带有“flushable”的所有键
- doctrine - 运行命令学说错误:模式:更新 symfony
- java - AWS DMS 服务在目标数据库上返回不同格式的 dateTime