switch的练习
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <body> <p>弹出问候分析:</p> <input type="text" id="xm"> <select name="" id="xb"> <option>性别</option> <option>男</option> <option>女</option> </select> <button id="wh">问候</button> </body> </html> <script> var wh = document.getElementById("wh"); wh.onclick = function(){ var xm = document.getElementById("xm").value; var xb = document.getElementById("xb").value; switch(xb){ case "性别": alert(xm + ",你好"); break; case "男": alert(xm + "先生,你好"); break; case "女": alert(xm + "女士,你好"); break; } } </script>