美文网首页
2019-06-12 计算器

2019-06-12 计算器

作者: 々_18C | 来源:发表于2019-06-12 20:32 被阅读0次

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="UTF-8">

    <title>计算器</title>

    <script type="text/javascript">

    window.onload = function(){

    var in01 = document.getElementById('input01')

    var in02 = document.getElementById('input02')

    var sel = document.getElementById('select')

    var bu = document.getElementById('btn')

    var a1 = Number(in01.value)

    bu.onclick =function(){

    if(sel.value == '0'){

    var result = Number(in01.value) +Number(in02.value);

    alert(result);

    }

    else if(sel.value == '1'){

    var result = Number(in01.value) - Number(in02.value);

    alert(result);

    }

    else if(sel.value == '2'){

    var result = Number(in01.value) * Number(in02.value);

    alert(result);

    }

    else if(sel.value == '3'){

    var result = Number(in01.value) / Number(in02.value);

    alert(result);

    }

    }

    }

    </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" onclick="javascript:button-onclick();"/>

    </body>

    </html>

    相关文章

      网友评论

          本文标题:2019-06-12 计算器

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