我正在尝试根据通过 javascript 设置但最初由用户通过表单字段 ( shipping_state
) 填充的全局变量禁用一周中的某些天。
<form id="myform">
<p>State: <select id="shipping_state" onchange="this.form.shipping_zip.value='';check_address('shipping');" name="shipping_state" class="txtBoxStyle">
<option value=""></option><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="DC">District of Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="PR">Puerto Rico</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VI">Virgin Islands</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select>
</p>
<p>Delivery Date:
<input name="my_deliverydate" type="text" id="datepicker"
size="30" />
</p>
<p>ALT Delivery Date:
<input name="my_altdeliverydate" type="text" id="altdatepicker"
size="30" />
</p>
<p>
Customer Comments:<br><textarea class="txtBoxStyle" id="custcomment" cols="55" rows="3"></textarea>
</p>
<p>
Combined Comment Field:<br><textarea class="txtBoxStyle" name="ocomment" id="compcomment" cols="55"
rows="3"></textarea>
</p>
<input type="button" name="submit" class="button" id="submit" value="Send" onclick="$('#compcomment').val('Delivery Date: ' + $('#altdatepicker').val() + ', Customer Comments: ' + $('#custcomment').val());"/>
这是Javascript
$(function () {
var date = new Date();
var currentMonth = date.getMonth(); // current month
var currentDate = date.getDate()+1; // current date
var currentYear = date.getFullYear(); //this year
$("#datepicker").datepicker({
dateFormat: "DD, d MM, yy", // set main date format to Wednesday, January 10th, 2013
altFormat: "yy-mm-dd", // set alt format to default
altField: "#altdatepicker", //set alt date field
changeMonth: true, // this will allow users to chnage the month
changeYear: true, // this will allow users to chnage the year
minDate: new Date(currentYear, currentMonth, currentDate),
beforeShowDay: function (date) {
if (date.getDay() === 0 || date.getDay() === 1 || date.getDay() === 2 || date.getDay() === 6) {
return [false, ''];
} else {
return [true, ''];
}
}
});
});
以下是我需要的所有日期限制:
- 没有周日、周一或周六。完毕。
- 今天、明天和之前的所有日期都处于非活动状态。完毕。
如果用户不选择田纳西州、肯塔基州、阿拉巴马州。
- 星期二需要不活动。
- Today + 2(后天)需要处于非活动状态。
理想情况下,在用户选择 a 之前,所有日期都将处于非活动状态shipping_state
。