正如我们所知,有些人不能正确地将词语大写,那些输入所有大写字母的人,然后还有那些不打扰大写字母的人。
我想知道如果这个人没有输入我在每个开关中放入的确切字符串,如何运行代码()
<html>
<body>
<script>
var days='thu';
switch(days)
{
case 'Mon':
document.write("Today is Monday");
break;
case 'Tue':
document.write("Today is Tuesday");
break;
case 'Wed':
document.write("Today is Wednesday");
break;
case 'Thu':
document.write("Today is Thursday");
break;
case 'Fri':
document.write("Today is Friday");
break;
default:
document.write("Weekend...!!!");
}
</script>
</body>
</html>
答案 0 :(得分:1)
在比较之前将输入转换为小写或大写。然后必须使用小写或大写的情况。
像
这样的东西var days='thu'; //or var days='Thu';
switch(days.toLowerCase())
因此代码适用于这两种情况。
case 'Mon':
case 'mon':
document.write("Today is Monday");
break;
case 'Ton':
case 'tue':
document.write("Today is Tuesday");
break;
如果您根本不想触摸日子,则以下方式有效。但我个人不喜欢它
do {
let array = try JSONSerialization.jsonObject(with: response.data!) as? NSArray
let countryListData = CountryList(fromArray: array!)
completionHandler(true, countryListData)
} catch {
print("Exception occured \(error))")
}
答案 1 :(得分:0)
您可以将其转换为小写然后检查。
switch(days.toLowerCase())
{
case 'mon':
document.write("Today is Monday");
break;
case 'tue':
document.write("Today is Tuesday");
break;
}
答案 2 :(得分:0)
我想知道即使这个人没有进入,代码也会如何运行 我放在每个开关()
中的确切字符串
您可以使用days
的前三个字符并将结果转换为 title-case
days = days.charAt(0).toUpperCase() + days.substring( 0,2 ); //put this line before `switch`
答案 3 :(得分:0)
首先你必须把它转换成大写或小写,然后才能匹配它
示例,如果您使用大写
switch(days.toUpperCase())
case 'MON':
document.write("Today is Monday");
break;
case 'TUE':
document.write("Today is Tuesday");
break;
case 'WED':
document.write("Today is Wednesday");
break;
case 'THU':
document.write("Today is Thursday");
break;
case 'FRI':
document.write("Today is Friday");
break;
default:
document.write("Weekend...!!!");
或者你可以像小写
那样做switch(days.toLowerCase())
case 'mon':
document.write("Today is Monday");
break;
case 'tue':
document.write("Today is Tuesday");
break;
case 'wed':
document.write("Today is Wednesday");
break;
case 'thu':
document.write("Today is Thursday");
break;
case 'fri':
document.write("Today is Friday");
break;
default:
document.write("Weekend...!!!");
答案 4 :(得分:0)
答案是一个新问题:或许不是来自输入?
<form method="post" action="">
The lower text:(try caps lock key to both!)<input type="text" name="" style="text-transform: lowercase;"><br>
This is caps by default:<input type="text" name="" style="text-transform: uppercase;">
</form>
&#13;
尝试 RUN CODE SNIPPET 按钮! 有时您可以避免来自反馈来源的操作