Created
January 6, 2014 05:32
-
-
Save sourcecodemart/8278698 to your computer and use it in GitHub Desktop.
jQuery datepicker highlight date with different color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>jQuery UI DatePicker</title> | |
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> | |
<script src="//code.jquery.com/jquery-1.9.1.js"></script> | |
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script> | |
<style> | |
.ui-highlight .ui-state-default{ | |
background: red !important; | |
border-color: red !important; | |
color: white !important; | |
} | |
</style> | |
<script type="text/javascript" language="javascript"> | |
var dates = ['2014-01-05','2014-01-15','2014-01-25']; | |
jQuery(function(){ | |
jQuery('input[type=text]').datepicker({ | |
changeMonth : true, | |
changeYear : true, | |
beforeShowDay : function(date){ | |
var y = date.getFullYear().toString(); // get full year | |
var m = (date.getMonth() + 1).toString(); // get month. | |
var d = date.getDate().toString(); // get Day | |
if(m.length == 1){ m = '0' + m; } // append zero(0) if single digit | |
if(d.length == 1){ d = '0' + d; } // append zero(0) if single digit | |
var currDate = y+'-'+m+'-'+d; | |
if(dates.indexOf(currDate) >= 0){ | |
return [true, "ui-highlight"]; | |
}else{ | |
return [true]; | |
} | |
} | |
}); | |
}) | |
</script> | |
</head> | |
<body> | |
<input type="text" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment