JavaScript练习(二)

来源:互联网 发布:通信行业 知乎 编辑:程序博客网 时间:2024/05/22 00:40

JavaScript练习二:

需求:计算查询时段。有订单查询页面,页面上显示两种查询时段,三天内、七天内。
用户选择某种查询时段,则需要提示查询的开始日期和结束日期。比如,用户单击“三天内”,则弹出从当前时间到三天后的时间信息。


=========================================答案==========================================

html代码:

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><span style="font:bold"> 2.Date 对象:订单时段查询 </span> <br /><input type="radio" name="r1" onclick="threeday()" />三天内<input type="radio"  name="r1" onclick="week()" />一周内</body><script>function threeday(){alert("开始日期为:"+GetDateStr(0)+"\n"+"结束日期为:"+GetDateStr(3));}function week(){alert("开始日期为:"+GetDateStr(0)+"\n"+"结束日期为:"+GetDateStr(7));}function GetDateStr(AddDay){var date = new Date();date.setDate(date.getDate()+AddDay); //获取几天后的信息var nowmonth = date.getMonth()+1;var nowweek = date.getDay();var nowyear = date.getFullYear();var nowday = date.getDate();switch(nowweek){case 1:nowweek='Monday';break;case 2:nowweek='Tuesday';break;case 3:nowweek='Wednesday';break;case 4:nowweek='Thursday'; break;case 5:nowweek='Friday';break;case 6:nowweek='Saturday';break;case 0:nowweek='Sunday';break;}return nowweek+","+nowmonth+" "+nowday+","+nowyear;}</script></html>

效果图如下:










3 0
原创粉丝点击