我需要休息十分钟,所以这是我的 jQuery 解决方案(假设你愿意使用它):
HTML
<select id="day0"></select><br />
<input id="day1" type="text" /><br />
<input id="day2" type="text" /><br />
<input id="day3" type="text" /><br />
<input id="day4" type="text" /><br />
<input id="day5" type="text" /><br />
<input id="day6" type="text" /><br />
JS:
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
function update(sel) {
var start = parseInt($(sel).val());
for (var i = 1; i <= days.length; i++) {
$('#day' + i).val(days[(i + start) % 7]);
}
}
$(function() {
// Find the select list
var $sel = $('#day0');
// Populate it with values from the 'days' array
$.each(days, function(i, v) {
$('<option value="' + i + '">' + v + '</option>').appendTo($sel);
});
// Hook up the 'update' function to run every time the
// selected option is changed
$sel.change(function() {
update(this);
});
// Force an initial update of the fields
update($sel);
});
工作演示