用js switch case解决 求各位前端大神帮下忙
发布网友
发布时间:2022-04-24 11:38
我来回答
共3个回答
热心网友
时间:2023-05-06 01:26
It's warm and wet in spring in Guang Dong. It's hot in summer. Children like to eat ice creams. But it does harm to our heaalth . It's cool in fall. People like to climb mountains in the season. It's beneficial to us. It's not so cold in winter,so we can play outside.. I like Guang Dong. Welcome to Guang Dong.
热心网友
时间:2023-05-06 01:26
只能用switch case的话,这样应该行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<div>hello world</div>
<script>
handleSex();
function handleSex(){
var sex = prompt('请输入你的性别,1为男,2为女');
switch(sex){
//输入的是字符串
case '1':
handleBloodboy()
break;
case '2':
handleBloodgirl()
break;
default:
alert('请正确输入性别');
handleSex();
}
}
function handleBloodboy() {
var blood = prompt('请输入你的血型,1为A,2为B,3为C,4为AB');
switch(blood){
case '1':
alert('男A追求完美,很执着')
break;
case '2':
alert('男B追求完美,很执着')
break;
case '3':
alert('男C追求完美,很执着')
break;
case '4':
alert('男AB追求完美,很执着')
break;
default:
alert('请正确输入血型');
handleBloodboy();
}
}
function handleBloodgirl() {
var blood = prompt('请输入你的血型,1为A,2为B,3为C,4为AB');
switch(blood){
case '1':
alert('女A追求完美,很执着')
break;
case '2':
alert('女B追求完美,很执着')
break;
case '3':
alert('女C追求完美,很执着')
break;
case '4':
alert('女AB追求完美,很执着')
break;
default:
alert('请正确输入血型');
handleBloodgirl();
}
}
</script>
</body>
</html>
热心网友
时间:2023-05-06 01:27
switch(n)
{
case 1:
执行代码块 1
break;
case 2:
执行代码块 2
break;
default:
n 与 case 1 和 case 2 不同时执行的代码
}