<html>
<head>
<script>
ChangeDate = function(param) {
var a = document.getElementById('beginTime').value;
var NowDate= new Date(Date.parse(a.replace(/\-/g,"/")));
NowDate.setDate(NowDate.getDate()+param);
document.getElementById('endTime').value=NowDate.toLocaleDateString().replace("年","-").replace("月","-").replace("日","").substr(0, 10);
};
//js截取字符串
function SubstrDemo(){
var s, ss; // 声明变量。
var s = "2011-11-27 星期日";
ss = s.substr(0, 10); // 获取子字符串。
alert(ss); // 返回 "Spain"。
}
function check_radio(){
var chkObjs = document.getElementsByName("rdOperatingMethods");
var a = document.getElementById('beginTime').value;
var NowDate= new Date(Date.parse(a.replace(/\-/g,"/")));
if(chkObjs[0].checked){
var a = document.getElementById('beginTime').value;
NowDate.setDate(NowDate.getDate()+0);
document.getElementById('endTime').value=NowDate.toLocaleDateString().replace("年","-").replace("月","-").replace("日","").substr(0, 10);
}
else if(chkObjs[1].checked){
var a = document.getElementById('beginTime').value;
NowDate.setDate(NowDate.getDate()+2);
document.getElementById('endTime').value=NowDate.toLocaleDateString().replace("年","-").replace("月","-").replace("日","").substr(0, 10);
}
if(chkObjs[2].checked){
var a = document.getElementById('beginTime').value;
NowDate.setDate(NowDate.getDate()+6);
document.getElementById('endTime').value=NowDate.toLocaleDateString().replace("年","-").replace("月","-").replace("日","").substr(0, 10);
}
}
</script>
</head>
<body>
<input type="button" value="测试" οnclick="SubstrDemo();"/>
<form id="fm1">
<table>
<tr>
<td>
<input id="rdOperatingMethods1" name="rdOperatingMethods" type="radio" value="0"
checked="checked" text="今日特价" οnclick='ChangeDate(0)' />今日特价
</td>
<td> <input id="rdOperatingMethods2" name="rdOperatingMethods" type="radio" value="0"
checked="checked" text="3日特价" οnclick='ChangeDate(2)'/>3日特价
</td>
<td> <input id="rdOperatingMethods3" name="rdOperatingMethods" type="radio" value="0"
checked="checked" text="7日特价" οnclick='ChangeDate(6)'/>7日特价
</td>
</tr>
<tr> <td colspan="3"> 开始日期: <input id="beginTime" name="beginTime" value="2011-11-25" Onchange="check_radio()"/> </td></tr>
<tr> <td colspan="3"> 结束日期: <input id="endTime" name="endTime" value="2011-11-26"> </td></tr>
</table>
</form>
</body>
</html>