<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function mylove(){
var mylove=document.getElementById("a").value;
if(mylove==1)
{alert("赵飞燕");
}
else if(mylove==2)
{alert("陈圆圆");
}
else if(mylove==3)
{alert("西施");
}
else if(mylove==4)
{alert("貂蝉");
}
else if(mylove==5)
{alert("王昭君")
}
else if(mylove==6)
{ alert("杨玉环")
}
else if(mylove==7)
{ alert("武则天")
}
else
{alert("你是同性恋啊?")}
}
</script>
</head>
<body>
<div>你到底爱谁?</div>
<input type="text" id="a">
<input type="button" value="爱的选择" onclick="mylove()"
</body>
</html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>switch</title> <script type="text/javascript"> function mylove(){ var mylove = document.getElementById('a').value; if(mylove == 1){ alert("赵飞燕"); } else if(mylove == 2){ alert("陈圆圆"); } else if(mylove == 3){ alert("西施"); } else if(mylove == 4){ alert("貂蝉"); } else if(mylove == 5){ alert("王昭君"); } else if(mylove == 6){ alert("杨玉环"); } else if(mylove == 7){ alert("武则天"); } else{ alert("你是同性恋啊?") } } </script> </head> <body> <div> 你到底爱谁? </div> <input type="text" id="a" /> <input type="button" value="爱的选择" onclick="mylove()"> </body> </html>
代码中所有的符号要用英文的符号。
document.write(陈圆圆);