<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>02if.html</title>
<script>
var age = parseInt(prompt("請輸入年齡","20"));//prompt跳出輸入框,20為預設輸入數值(回傳值為String),parseInt把傳值轉為數字
if (isNaN(age))
document.write("請輸入數字");
else if (0 < age && age <= 6 || 65 <= age)//記得要加&&,不可以直接用0<age<=6
document.write("免票");
else if (6 < age && age <= 25)
document.write("學生票");
else if (25 < age && age <= 65)
document.write("全票");
document.write("<hr>");
var a = 10, b = 20;
if (a > b)
document.write("a > b");
else
document.write("a<b");//注意「<」的前後需要有空格,不然會出錯(誤以為你要打括號),可以打<取代
</script>
</head>
<body>
</body>
</html>
留言列表