我不能为我的生活解决为什么这段代码不起作用。我确信我做的事情非常愚蠢,但我找不到它!我目前只是试图禁用所有日期栏“7-8-2013”。任何有关这方面的帮助将不胜感激。谢谢!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Calender Control Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
var enableDays = ["7-8-2013"];
$(function enableAllTheseDays(date) {
var m = date.getMonth(), var d = date.getDate(), var y = date.getFullYear();
for (i = 0; i < enableDays.length; i++) {
if($.inArray((d+1) + '-' + m + '-' + y,enableDays) != -1) {
return [true];
}
}
return [false];
$('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
</script>
</head>
<body>
<div id="datepicker"></div>
</body>
</html>
答案 0 :(得分:11)
尝试
jQuery(function(){
var enableDays = ["7-8-2013"];
function enableAllTheseDays(date) {
var sdate = $.datepicker.formatDate( 'd-m-yy', date)
if($.inArray(sdate, enableDays) != -1) {
return [true];
}
return [false];
}
$('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
})
演示:Fiddle
答案 1 :(得分:1)
试试这个
$(document).ready(){
var enableDays = ["7-8-2013"];
function enableAllTheseDays(date) {
var sdate = $.datepicker.formatDate( 'd-m-yy', date)
if($.inArray(sdate, enableDays) != -1) {
return [true];
}
return [false];
}
$('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
})
希望它会有所帮助