根据下图显示开始日期和结束日期。流程是这样的:
观点:
以下是代码: JAVASCRIPT
function getDate(id) {
id = id.match(/\d+/);
var sd = document.getElementById('start_date'+ id).value;
//var fd = document.getelementById('firstdate'+ id).value;
//var ed = document.getElementById('end_date'+ id).value;
var d = document.getElementById('duration' + id).value;
var m = document.getElementById('marking' + id).value;
var date = new Date(sd);
var newdate = new Date(date);
var durations = parseInt(d);
var markings = parseInt(m);
if ( markings == 0 || markings == 1 )
{
newdate.setDate(newdate.getDate());
}
else if ( markings == 2 )
{
newdate.setDate((newdate.getDate() + durations)-1);
}
else if ( markings == 3 )
{
newdate.setDate(newdate.getDate() + durations);
}
//newdate.setDate((newdate.getDate() + durations)-1);
var dd = newdate.getDate();
var mm = newdate.getMonth()+1;
var y = newdate.getFullYear();
var someFormattedDate = y + '-' + mm + '-' + dd;
document.getElementById('end_date' + id).value = someFormattedDate;
HTML
<td style="font-family:century-gothic">
<font color="black">Bina Stor</font>
</td>
<td>
<input type="text" id="task_mark1" class="task_mark" name="task_mark" value="T1" />
</td>
<td>
<input type="text" id="marking1" class="marking" name="marking" value="0" />
</td>
<td>
<input type="text" id="destination_marking1" class="destination_marking" name="destination_marking" value="0" />
</td>
<td>
<input type="text" id="days1" class="days" name="days" value="0" />
</td>
<td>
<input type="text" id="duration1" class="duration" name="duration" value="1" />
</td>
<td>
<input type="text" id="start_date1" class="start_date" name="start_date" value="2017-02-02" />
</td>
<td>
<input type="text" id="end_date1" class="end_date" name="end_date" value="" />
</td>
<td align="center">
<input type="button" id ="btn1" value="GENERATE" name="action" class ="submit-green" onclick="getDate(this.id)"/>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td style="font-family:century-gothic" >
<font color="black">Side Rail</font>
</td>
<td>
<input type="text" id="task_mark2" class="task_mark" name="task_mark" value="T2" />
</td>
<td>
<input type="text" id="marking2" class="marking" name="marking" value="3" />
</td>
<td>
<input type="text" id="destination_marking2" class="destination_marking" name="destination_marking" value="0" />
</td>
<td>
<input type="text" id="days2" class="days" name="days" value="0" />
</td>
<td>
<input type="text" id="duration2" class="duration" name="duration" value="1" />
</td>
<td>
<input type="text" id="start_date2" class="start_date" name="start_date" value="" />
</td>
<td>
<input type="text" id="end_date2" class="end_date" name="end_date" value="" />
</td>
<td align="center">
<input type="button" id ="btn2" value="GENERATE" name="action" class ="submit-green" onclick="getDate(this.id)"/>
</td>
</tr>