38、可以查询星期的代码

38、可以查询星期的代码

<html>

<head>

<title>网页特效---星期查询!可设置任意、年、月、日</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

var mtend = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var opt = new Array("过去时间","将来时间");

function getDateInfo() {

var y = document.form.year.value;

var m = document.form.month.options[document.form.month.options.selectedIndex].value;

var d = document.form.day.options[document.form.day.options.selectedIndex].value;

var hlpr = mtend[m];

if (d < mtend[m] + 1) {

if (m == 1 && y % 4 == 0) { hlpr++; }

var c = new Date(y,m,d);

var dayOfWeek = c.getDay();

document.form.dw.value = days[dayOfWeek];

if(c.getTime() > new Date().getTime()) {

document.form.time.value = opt[1];

}

else {

document.form.time.value = opt[0];

   }

}

else {

alert("这一天"+months[m]+" "+d+", "+y+"是不存在的.\n请重新选择.");

   }

}

function setY() {

var y = new Date().getYear();

if (y < 2000) y += 1900;

document.form.year.value = y;

}

//  End -->

</script>

<form name="form">

<p><input type="text" name="year" size="8" value="2004"> <select name="month" size="1">

<option selected value="0">1</option>

<option value="1">2 </option>

<option value="2">3 </option>

<option value="3">4 </option>

<option value="4">5 </option>

<option value="5">6 </option>

<option value="6">7 </option>

<option value="7">8 </option>

<option value="8">9 </option>

<option value="9">10 </option>

<option value="10">11 </option>

<option value="11">12 </option>

</select><select name="day" size="1">

<option selected value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

<option value="6">6</option>

<option value="7">7</option>

<option value="8">8</option>

<option value="9">9</option>

<option value="10">10</option>

<option value="11">11</option>

<option value="12">12</option>

<option value="13">13</option>

<option value="14">14</option>

<option value="15">15</option>

<option value="16">16</option>

<option value="17">17</option>

<option value="18">18</option>

<option value="19">19</option>

<option value="20">20</option>

<option value="21">21</option>

<option value="22">22</option>

<option value="23">23</option>

<option value="24">24</option>

<option value="25">25</option>

<option value="26">26</option>

<option value="27">27</option>

<option value="28">28</option>

<option value="29">29</option>

<option value="30">30</option>

<option value="31">31</option>

</select> <input type="button"

value="看看这天的信息" name="gdi" onClick="getDateInfo()"></p>

<p>这里显示是星期几:<input type="text" name="dw" size="12">时间状态:<input type="text"

name="time" size="10"></p>

</form>

 

</body>

</html>

 

Write a comment

Comments: 0