close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h2>不同數字出現不同結果</h2>
<input type="number" name="" max='5' min="0" id="number">
<button id="btn">按我</button>
<h2 id="result"></h2>
<script type="text/javascript">
document.getElementById('btn').onclick=function(){
var number=document.getElementById('number').value;
number=parseInt(number);
var result='';
switch(number){
case 1:
result='一號餐是麥克炸機喔';
break;
case 2:
result='二號不是噩耗啦';
break;
case 3:
result='三號外傳天之痕';
break;
case 4:
result='四號位置要找速度快的';
break;
case 5:
result='五號有效喔';
break;
default:
result='輸入1-5之間吧';
break;
}
document.getElementById('result').textContent=result;
}
</script>
</body>
</html>
全站熱搜
留言列表