Javascript IF语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript IF语句相关的知识,希望对你有一定的参考价值。

  1. <head>
  2. <script language="javascript">
  3.  
  4. var secret_password = "jasmine";
  5. var entered_password = prompt("please enter password", " ");
  6.  
  7. if (entered_password != secret_password)
  8. {
  9. document.write("incorrect");
  10. }
  11. else
  12. {
  13. document.write("welcome");
  14. }
  15.  
  16. </script>
  17. </head>
  18. <body>
  19.  
  20. </body>
  21. </html>
  22.  
  23.  
  24.  
  25. <html>
  26. <head>
  27. <script language="javascript">
  28.  
  29. var secret_password = "jasmine";
  30. var usernmae = "password";
  31. var entered_password = prompt("please enter password", " ");
  32. var entered_username = prompt("please enter username", " ");
  33.  
  34. if ((entered_password == secret_password) && (entered_username == username))
  35. {
  36. document.write("correct");
  37. }
  38. else
  39. {
  40. document.write("try again");
  41. }
  42.  
  43. </script>
  44. </head>
  45. <body>
  46.  
  47. </body>
  48. </html>
  49.  
  50.  
  51.  
  52. <html>
  53. <head>
  54. <script language="javascript">
  55.  
  56. var admin = admin
  57. var developer = "mike";
  58. var user = "user";
  59.  
  60. var entered_password = prompt("please enter password", " ");
  61.  
  62. switch (entered_password)
  63. {
  64. case "admin": alert("you are admin"); break
  65. case "mike": alert("you are a developer"); break
  66. case "user": alert("you are a user"); break
  67. default: alert("password Incorrect!!"); break
  68. }
  69.  
  70. </script>
  71. </head>
  72. <body>
  73.  
  74. </body>
  75. </html>

以上是关于Javascript IF语句的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript Javascript IF语句

JavaScript学习——JavaScript 条件 语句 switch语句 while语句

JavaScript:关于数组声明的 If 语句

JavaScript 流程控制-实际案例学习if语句

JavaScript If...ElseSwitchForWhileBreakContinue语句

JavaScript 单行 'if' 语句 - 最佳语法,这个替代方案? [关闭]