在java脚本中显示星期几 [英] displaying days of the week in java script

查看:95
本文介绍了在java脚本中显示星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 - 创建一个带有文本输入字段和按钮的HTML表单。当在文本输入字段中输入一个数字并单击该按钮时,将调用名为DayOfTheWeek()的Javascript函数。此函数使用switch语句来确定与输入的数字相对应的星期几,即如果输入的数字是1,则显示消息It's Monday,如果输入的数字是2,则显示消息It's Tuesday并且等等。如果输入的数字不在1-7之间,则会显示消息不是一周中的有效日期。

I need to - Create a HTML form with a text entry field and a button.. When a number is entered in the text entry field and the button clicked a Javascript function called DayOfTheWeek() is invoked. This function uses a switch statement to determine the day of the week corresponding to the number entered, i.e if the number entered is 1 the message "It’s Monday" is displayed, if the number entered is 2 the message "It’s Tuesday" is displayed and so on. If a number which is not between 1-7 is entered then the message "Not a valid day of the week" is displayed.

my html

<input type="text" name="text1"/>

<input type="button" value="Click me" onclick="days(text1.value);"/>

我的java脚本

function days(dayOfTheWeek)
{
switch (dayOfTheWeek) {

case "1": 
    alert("It\’s Monday");
        break;
case "2":
        alert("It\’s Tuesday");
    break;

case "3":
        alert("It\’s Wednesday");
    break;

case "4":
        alert("It\’s Thursday");
    break;

case "5":
        alert("It\’s Friday");
    break;

case "6":
        alert("It\’s Saturday");
    break;

case "7":
        alert("It\’s Sunday");
    break;

default:
        alert("Not a valid day");
    break;  

}
}

请帮助我一直收到错误用firebug说几天不定义

PLEASE HELP I keep getting an error with firebug saying days is not defind

推荐答案

function days(dayOfTheWeek) {
  var weekday=new Array(7);
  weekday[0]="Sunday";
  weekday[1]="Monday";
  weekday[2]="Tuesday";
  weekday[3]="Wednesday";
  weekday[4]="Thursday";
  weekday[5]="Friday";
  weekday[6]="Saturday";

  var n = weekday[dayOfTheWeek];
  return n;
}

这篇关于在java脚本中显示星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆