我想强调一些定制的日期:这是我到目前为止所拥有的
if ( jQuery('.datepicker').length ) {
jQuery('.datepicker').each(function (i) {
var $item = jQuery(this);
var fechas = $item.data('fechas');
var options = {
'display' : $item.data('display') == '' ? '' : $item.data('display'),
beforeShowDay: function(date) {
console.log(date);
if ( fechas.length ) {
for( var i = 0; i < fechas.length; i++ ) {
if ( fechas[i] == date) {
return [true, 'css-class-to-highlight', 'tooltipText'];
}
}
}
}
}
$item.datepicker( options );
});
}
但是我得到了这个错误
Uncaught TypeError: Cannot read property '0' of undefined
http://jsfiddle.net/34jLb8o3/2/
问题是,我想突出这个日期,不管现在的日期,我已经看到了像这一个这样的答案,但我认为它们不适用于这里,对吗?
发布于 2014-10-10 09:17:45
这似乎更好:http://jsfiddle.net/34jLb8o3/8/
jQuery(function(){
jQuery('.datepicker').each(function (i) {
var $item = jQuery(this);
var fechas = $item.data('fechas');
var options = {
'dateFormat' : 'dd/mm/yy',
'display' : $item.data('display') == '' ? '' : $item.data('display'),
beforeShowDay: function(date) {
if ( fechas.length ) {
var datestr = [ date.getDate(), date.getMonth()+1, date.getFullYear()];
datestr = datestr.join('/');
console.log(datestr);
if ($.inArray(datestr, fechas) != -1) {
return [true, 'css-class-to-highlight', 'tooltipText'];
} else {
return [false, 'css-normal-class', 'no-highlight'];
}
}
}
}
$item.datepicker( options );
});
});
发布于 2014-10-10 09:44:05
下面是用于突出显示2014年10月2日的查询语句
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<style>
.ui-state-highlight {
background: red !important;
}
</style>
<script type="text/javascript">
$(function () {
$("#date").datepicker();
$("#date").bind('click', function () { highLightDate(2014, 9, 31); });
})
function highLightDate (_year,_month,_day){
$('[data-year=' + _year + '][data-month=' + _month + '] > a:contains(' + _day + ')')
.filter(function (index) {
return $(this).text() == _day;
})
.addClass('ui-state-highlight');
}
</script>
</head>
<body>
<input type="text" width="100" id="date" />
</body>
</html>
试试这段代码,它完全可以用在我的末端。希望这能解决你的问题。
发布于 2014-10-10 10:20:47
您可以使用beforeShowDay,按照文档返回数组
http://jsbin.com/borum/2/edit?js,output
$(function() {
var dates = ["10/10/2014","12/10/2014","13/10/2014"];
var options = {
dateFormat : 'dd/mm/yy',
beforeShowDay: function(date) {
formattedDate = $.datepicker.formatDate('dd/mm/yy', date);
if(dates.indexOf(formattedDate) === -1){
return [false];
}
else{
return [true];
}
}
};
$( "#datepicker" ).datepicker( options );
});
https://stackoverflow.com/questions/26295853
复制相似问题