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>

 

posted @ 2019-01-12 10:50  OH-MY-GOD  阅读(187)  评论(0编辑  收藏  举报