$(function() { $.datepicker.setDefaults($.datepicker.regional["ja"]); //土日を選択した場合は時間帯選択の「18時以降(平日のみ)」を非表示にする function doSomething() { var pmtc = $('input[value^="PMTC(クリーニング)"]'); var officeW = $('input[value^="オフィスホワイトニング"]'); if($(this).hasClass('day1')){ $('select[name="date-hope1-time"]').prop('selectedIndex', 0); var date1 = $('.day1').datepicker('getDate'); var day1 = date1.getDay(); if (day1 == 6 || day1 == 0) { //土日は18時以降選べない $('[data-name="date-hope1-time"] select option:last-child').prop('disabled', true); } else if ($(pmtc).prop("checked") && !(day1 == 6 || day1 == 0)) { //PMTCチェックしてると平日18時以降選べない $('[data-name="date-hope1-time"] select option:last-child').prop('disabled', true); } else if ($(officeW).prop("checked") && !(day1 == 6 || day1 == 0)) { //オフィスホワイトニングチェックしてると平日18時以降選べない $('[data-name="date-hope1-time"] select option:last-child').prop('disabled', true); } else{ $('[data-name="date-hope1-time"] select option:last-child').prop('disabled', false); } } if($(this).hasClass('day2')){ $('select[name="date-hope2-time"]').prop('selectedIndex', 0); var date2 = $('.day2').datepicker('getDate'); var day2 = date2.getDay(); if (day2 == 6 || day2 == 0) { $('[data-name="date-hope2-time"] select option:last-child').prop('disabled', true); } else if ($(pmtc).prop("checked") && !(day2 == 6 || day2 == 0)) { $('[data-name="date-hope2-time"] select option:last-child').prop('disabled', true); } else if ($(officeW).prop("checked") && !(day2 == 6 || day2 == 0)) { $('[data-name="date-hope2-time"] select option:last-child').prop('disabled', true); } else{ $('[data-name="date-hope2-time"] select option:last-child').prop('disabled', false); } } if($(this).hasClass('day3')){ $('select[name="date-hope3-time"]').prop('selectedIndex', 0); var date3 = $('.day3').datepicker('getDate'); var day3 = date3.getDay(); if (day3 == 6 || day3 == 0) { $('[data-name="date-hope3-time"] select option:last-child').prop('disabled', true); } else if ($(pmtc).prop("checked") && !(day2 == 6 || day2 == 0)) { $('[data-name="date-hope3-time"] select option:last-child').prop('disabled', true); } else if ($(officeW).prop("checked") && !(day2 == 6 || day2 == 0)) { $('[data-name="date-hope3-time"] select option:last-child').prop('disabled', true); } else{ $('[data-name="date-hope3-time"] select option:last-child').prop('disabled', false); } } $(pmtc).on('click', function() { $(".date_hope").val(''); $(".time_hope").prop('selectedIndex', 0); }); $(officeW).on('click', function() { $(".date_hope").val(''); $(".time_hope").prop('selectedIndex', 0); }); } var numberOfMonths; if (window.matchMedia && window.matchMedia('(max-device-width: 640px)').matches) { // smartphone numberOfMonths = 1; } else { // pc numberOfMonths = 2; } $(".date_hope").datepicker( { numberOfMonths: numberOfMonths, autoSize: true,//テキストボックスの幅を自動設定 firstDay: 0, // 日曜始まり dateFormat: 'yy/mm/dd', minDate: '2024/05/01',//上記で判定した翌日・翌々日の日付を指定 maxDate: '+3m', onSelect: doSomething, beforeShowDay : function(date) {//以下、休業日設定をする日付を記載 var dateFormat = 'yy/mm/dd'; var disableDates = [ "2023/01/01","2023/01/02","2023/01/03","2023/01/09","2023/02/11","2023/02/23","2023/03/21","2023/04/27","2023/04/28","2023/04/29","2023/05/03","2023/05/04","2023/05/05","2023/07/17","2023/08/11","2023/09/18","2023/09/23","2023/10/09","2023/11/03","2023/11/23","2023/12/29","2023/12/30","2023/12/31","2024/01/01","2024/01/02","2024/01/03","2024/01/08","2024/02/12","2024/02/23","2024/03/20" ]; var disableDate = $.datepicker.formatDate(dateFormat, date); var pmtc = $('input[value^="PMTC(クリーニング)"]'); var officeW = $('input[value^="オフィスホワイトニング"]'); // if (date.getDay() == 3) { // // 水曜日 // return [false, 'ui-state-disabled']; // } // else { // // 水曜日以外 // return [( disableDates.indexOf(disableDate) == -1 ), "", "診療日"]; // } return [( disableDates.indexOf(disableDate) == -1 ), "", "診療日"]; } }); $('.date_hope').attr('readonly',true);//スマホでキーボードを表示しない });