javascript if elseif 语句


javascript if elseif 语句

<html>
   <body>

      <script type = "text/javascript">
         <!--
            var book = "maths";
            if( book == "history" ) {
               document.write("<b>History Book</b>");
            }

            else if( book == "maths" ) {
               document.write("<b>Maths Book</b>");
            }

            else if( book == "economics" ) {
               document.write("<b>Economics Book</b>");
            }

            else {
               document.write("<b>Unknown Book</b>");
            }
         //-->
      </script>

      <p>Set the variable to different value and then try...</p>
   </body>
<html>