像这样:
function addHoursRangeToSelect(select, from, to){
$(select).empty();
for(var h=from; h<=to; h++){
$("<option />").val(h).html(addZero(n)).appendTo($(select));
}
function addZero(n){ return (n < 10 ? "0"+n : ""+n); }
}
$("#startDate").change(function(){
var startHH1, endHH1;
switch($(this).val()){
case "2011-05-06": //Assuming "2011-05-06" is the value of 'Fri, 06 May 2011' option
startHH1 = 10; endHH1 = 23; break;
case "2011-05-07": //Assuming "2011-05-06" is the value of 'Sat, 07 may 2011' option
startHH1 = 0; endHH1 = 10; break;
}
addHoursRangeToSelect("#startHH1", startHH1, endHH1);
});
希望这有助于。 干杯
谢谢@Edgar。我想我一定没有解释清楚。我们只需要从10,11 ..... 23中填入Start Hour Drop down(在您的解决方案中为#startHH2),对于case1则填充0,1,2 ... 10。我更新了有问题的图片,以便它只显示1下拉。 – 2011-05-07 00:33:34
@flybyte:哦,我现在明白了。我正在更新我的解决方案以满足此要求。 – 2011-05-07 02:47:09