<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input id="y" type="text" placeholder="年" /> <input id="m" type="text" placeholder="月" />
<nput id="d" type="text" placeholder="日" /> <br /> <input type="button" id="btn" value="计算星期几" /> <input type="text"
id="w" placeholder="星期几">
<script>
var y = document.getElementById('y')
var m = document.getElementById('m')
var d = document.getElementById('d')
var w = document.getElementById('w')
var btn = document.getElementById('btn')
btn.onclick = function () {
var a = ''
a = y.value + '/' + m.value + '/' + d.value
var date = new Date(a)
var week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
w.value = week[date.getDay()]
}
</script>
</body>
</script>
</body>
</html>
一般一星期顺序如下:星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
function getMyDay(date){
var week
if(date.getDay()==0) week="周日"
if(date.getDay()==1) week="周一"
if(date.getDay()==2) week="周二"
if(date.getDay()==3) week="周三"
if(date.getDay()==4) week="周四"
if(date.getDay()==5) week="周五"
if(date.getDay()==6) week="周六"
return week
}
var w1 = getMyDay(new Date("2015-7-12"))
1、这可以用JavaScript的Date对象的getDay方法。如:获取当天是星期几,则为:new Date().getDay()//返回0-6,0对应星期天,1-6对应星期一到星期六2、如果想给定某个时间是星期几,则应该把字符串转化为Date。如:new Date('2015-09-27').getDay()//将返回0,表示星期天3、具体,可以参见http://www.w3school.com.cn/jsref/jsref_obj_date.asp里对date的介绍