<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>获得星期</title><script type="text/javascript"> function con(){ var y,m,d; y= document.getElementById("year").value; m= document.getElementById("mounth").value-1; d= document.getElementById("day").value; var myday=new Date(y,m,d); var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var answer=myday.getDay(); } function count(){ document.write("你输入的时间应该是"+ weekday[answer]); }</script></head><body><form> <input type="text" name="年" id="year" >请输入您想获得的年份</input> <input type="text" name="年" id="mounth" >请输入您想获得的月份</input> <input type="text" name="年" id="day" >请输入您想获得的日期</input> <input type="button" name="年" id="click" onclick="count()" value="点击确认"/></form></body></html>
4 回答
weibo_Highness学
TA贡献7条经验 获得超2个赞
weekday 和 answer 变量定义域错误,导致 count函数访问不到,把weekday 和 answer 定义在函数外边作为全局变量即可
添加回答
举报
0/150
提交
取消