a
jqueryのindatepickerの背景色を変更する方法if statement
ここに私のコードでif statement
は、trueの場合、日付は無効になるというステートメントがありますが、a
無効にするのではなく、indatepickerの背景色を変更したいと思います。この問題から私を助けてください、tyia。
//これがスクリプトです
<script type='text/javascript'>
$(document).ready(function() {
// var unavailableDates = ["18-8-2018", "19-8-2018", "20-8-2018"]; // sample dates in day month year format
var unavailableDates = <?php echo $jsonencode; ?>; // array from the condition above
console.log(unavailableDates);
function unavailable(date) {
// ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
// +1 because array starts at index 0
// without + 1 january will start on index 0 instead of index 1
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
// to check if dmy exists in the variable array
// inArray default result will be -1 meaning true. to reverse != -1
if ($.inArray(dmy, unavailableDates) == -1)
{
return [true, ""];
// if true dates that exist in the array will be disabled
}
else {
return [false, "", "Unavailable"];
}
}
$(document).ready(function() { // to load jquery after the whole page loads
$("#datepicker").datepicker({
dateFormat: 'd-m-yy', // date format that would display on the textbox
//mindate = start of date from current
minDate: 0,
// to disable specific date unavailable function is called
beforeShowDay: unavailable // function unavailable
});
});
});
</script>
デートピッカー
<input id="datepicker" name="dates" readonly='true'>
参照
<link rel="stylesheet" type="text/css" href="datejs/jquery-ui.css">
<script src="datejs/jquery.js"></script>
<script src="datejs/jquery-ui.js"></script>
この行を変更します。
return [false, "", "Unavailable"];
これに:
return [true, "different-background", "Unavailable"];
そして、different-background
好きなようにクラスのスタイルを設定できます。
<style> .different-background a { background-color: red !important; } </style>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加