JavaScript 簡單的判斷語句
阿新 • • 發佈:2018-12-13
程式碼片段:
<html> <body> <form name="form1"> 輸入年齡:<input type="text" name="age" /><br> <input type="button" name="button" value="提交" onClick="myCheck()"/> </form> </body> <script language="javascript"> function myCheck(){ if(form1.age.value == ""){ alert("請輸入年齡!"); form1.age.focus; return false; }else{ var i = 18; var j = 30; var k = 50; var youAge = form1.age.value; if(youAge < i){ alert("你還沒成年哦!"); }else if(i <= youAge && youAge < j){ alert("你是一個青年人了!"); }else if(j <= youAge && youAge < k){ alert("你步入壯年啦!"); }else{ alert("珍惜老年生活!"); } } } </script> </html>
結果顯示: