我有一个 JQuery 日期选择器范围。我想在它上面添加两个箭头按钮。当按下左箭头时,两个日期都会减少一天。对面是右边。
无论我按哪个箭头,我目前都将日期设置为当前日期。
我只发布了一些代码片段,因为其中大部分都非常相似(左箭头与右箭头以及 startdate 与 enddate)
<script>
$(function() {
$( "#startdate" ).datepicker({
onClose: function( selectedDate ) {
$( "#enddate" ).datepicker( "option", "minDate", selectedDate );
}
});
<script>
<script language="Javascript" type="text/javascript">
function reduceDate()
{
var strCurrStart = $( "#startdate" ).datepicker( "getDate" );
var strCurrEnd = $( "#enddate" ).datepicker( "getDate" );
var dateCurrStart = new Date(Date.parse(strCurrStart));
var dateCurrEnd = new Date(Date.parse(strCurrEnd));
dateCurrStart.setDate(dateCurrStart.getDate() - 1);
dateCurrEnd.setDate(dateCurrEnd.getDate() - 1);
var dateNewStart = dateCurrStart.toDateString();
var dateNewEnd = dateCurrEnd.toDateString();
dateNewStart = new Date( Date.parse(dateNewStart));
dateNewEnd = new Date( Date.parse(dateNewEnd));
$( "#startdate" ).datepicker( "setDate", "dateNewStart" );
$( "#enddate" ).datepicker( "setDate", "dateNewEnd" );
return 1;
}
</script>
<div align="center">
<a href="#" onClick="return reduceDate();"><img src="Black-Left-Arrow.png" alt="-1d" border="0" height="15"></a> <a href="#" onClick="return increaseDate();"><img src="Black-Right-Arrow.png" alt="-1d" border="0" height="15"></a> <br>
<form>
<label for="startdate">From</label>
<input type="text" id="startdate" name="startdate" value= <%=$strStartDate%> />
<label for="enddate">to</label>
<input type="text" id="enddate" name="enddate" value= <%=$strEndDate%>>
<input type="submit" value="Update" ><input type="hidden" name= "query" value= <%=$query%> />
</form>
</div>