我正在尝试创建一个脚本,根据下拉框的值,它会自动填充一个与给定日期相距四分之一、两个季度或两个季度的文本框。因此,对于第 1 季度的值,box1 将是“1-1-2011”,而 box2 将填充“1-4-2011”。目前,在更改日期方面我看不到任何事情发生。我是一个初学者,几天来一直在努力完成这项工作。抱歉,如果我忽略了一个明显的问题。
要素如下:
<div>
<label>Periode</label>
<select name="pchoice" id="pchoice" onChange="calcdates()">
<option value="moddate">Zelf invoeren</option>
<option value="quarter1">1e Kwartaal</option>
<option value="quarter2">2e Kwartaal</option>
<option value="quarter3">3e Kwartaal</option>
</select>
</div>
<div>
<label>Datum </label> <input id="startDate" name="startDate" maxlength="10" style="width: 6em;"/> t/m <input id="endDate" name="endDate" maxlength="10" style="width: 6em;"/>
</div>
剧本:
<script type="text/javascript" charset="utf-8">
$(document).ready(
function() {
var datepickerparam = {
dateFormat : 'dd-mm-yy',
dayNamesMin : [ 'Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za' ],
monthNames : [ 'Januari', 'Februari', 'Maart', 'April','Mei', 'Juni','Juli', 'Augustus', 'September','Oktober', 'November', 'December' ]
};
$("#startDate").datepicker(datepickerparam);
$("#endDate").datepicker(datepickerparam);
});
function calcdates(){
var w = document.pchoice.selectedIndex;
var selected_text = document.pchoice.options[w].value;
var commencedate = new Date("01-01-2011");
var end = new Date();
//make dynamic with some variable
switch(selected_text){
case "quarter1":
$("#startDate").val(commencedate);
$("#endDate").val(commencedate+90);
break;
case "quarter2":
$("#startDate").value='12-03-2011';
$("#endDate").value='12-06-2011';
break;
case "quarter3":
$("#startDate").value='13-06-2011';
$("#endDate").value='13-09-2011';
break;
case "moddate":
$("#startDate").value = '';
$("#endDate").value ='';
break;
}
}