Today, when doing practice code, use the switch to judge the statement, the code is as follows
<script>
function Showuser (SSS) { var shen=sss; Alert (typeof SSS); Switch (shen) {case 1: x= "Zhang San"; break; Case 2: x= "John Doe"; break; Case 3: x= "Wang er"; break; Case 4: x= "Chen"; break; } document.getElementById ("Mydiv"). Innerhtml=x;}
</script><form> Select a user:<select name= "users" onchange= "Showuser (this.value)" ><option Value= "1" >peter griffin</option><option value= "2" >lois griffin</option><option value= "3" >glenn quagmire</option><option value= "4" >joseph Swanson</option></select></form >
<div id= "Mydiv" ></div>
The code is simple, the user chooses to make a judgment, then in the Mydiv section to display the corresponding text. But how to test can not display properly, after the online review know, in the switch used in the "= = =" Judgment, that is, at the same time to judge the type of parameters, after the code can be modified to normal use.
The modified function code is as follows:
function Showuser (SSS) { var shen=sss; Alert (typeof SSS); Switch (shen) {case "1": x= "Today it ' s Monday"; break; Case "2": x= "Today it ' s Tuesday"; break; Case "3": x= "Today it ' s Wednesday"; break; Case "4": x= "Today it ' s Thursday"; break; } document.getElementById ("Mydiv"). Innerhtml=x;}
What to consider in JS switch