美文网首页
2018-12-08

2018-12-08

作者: 11bbc2c5d0c6 | 来源:发表于2018-12-08 13:53 被阅读0次
1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
    window.onload = function () {
        var oInput01 = document.getElementById('input01');
        var oInput02 = document.getElementById('input02');
        var oSelect = document.getElementById('select');
        var oBtn = document.getElementById('btn');
        oBtn.onclick = function () {
            var vl01 = oInput01.value;
            var vl02 = oInput02.value;
            if (vl01=="" || vl02==""){
                alert('输入不能为空!');
                return;
            }
            if (isNaN(vl01) || isNaN(vl02)){
                alert('请输入数字!');
                return;
            }
            switch(oSelect.value){
                case '0':
                    alert((parseFloat(vl01)*100 + parseFloat(vl02)*100)/100);
                    break;
                case '1':
                    alert((parseFloat(vl01)*100 - parseFloat(vl02)*100)/100);
                    break;
                case '2':
                    alert((parseFloat(vl01)*100) * (parseFloat(vl02)*100)/10000);
                    break;
                case '3':
                    alert((parseFloat(vl01)*100) / (parseFloat(vl02)*100));
                    break;
            }
            }
        }
</script>

</head>
<body>
<h1>计算器</h1>
<input type="text" name="" id="input01">
<select id="select">
    <option value="0">+</option>
    <option value="1">-</option>
    <option value="2">*</option>
    <option value="3">/</option>
</select>
<input type="text" name="" id="input02" />
<input type="button" name="" value="计算" id="btn">
</body>
</html>
2
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>switch练习1</title>
    <script type="text/javascript">
        /*
         * 对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'
         */
        var score = Number(prompt("请输入成绩:"))
        switch(parseInt(score/60)){
            case 1:
                alert('合格');
                break;
            case 0:
                alert('不合格');
                break;
        }
    </script>
<body>
</body>
</html>
3
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>switch练习2</title>
    <script type="text/javascript">
        /*
         * 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
         */
        var num = Number(prompt("numbe"))
        switch(num){
            case num = 1:
                alert('sunday')
                break;
                case 2:
                alert('monday');
                break;
            case 3:
                alert('tuesday');
                break;
            case 4:
                alert('Wednesday');
                break;
            case 5:
                alert('Thursday');
                break;
            case 6:
                alert('Friday');
                break;
            case 7:
                alert('Saturday');
                break;
            default:
                alert('erro');
                break;
        }
    </script>
<body>
</body>
</html>

相关文章

网友评论

      本文标题:2018-12-08

      本文链接:https://www.haomeiwen.com/subject/mqdqhqtx.html