简易计算器

简易计算器



超短源代码:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>简易计算器</title>
    <script>
        function lst() { return Number(document.getElementById('lst').value); }
        function rst() { return Number(document.getElementById('rst').value); }
        function ans(v) { document.getElementById('ans').value = v; }
    </script>
</head>

<body>
    <h1>简易计算器</h1>
    <label for="lst">第一个数</label> <input id="lst" type="number"><br>
    <label for="rst">第二个数</label> <input id="rst" type="number"><br>
    <input type="button" value="+" onclick="ans(lst()+rst())">&emsp;
    <input type="button" value="-" onclick="ans(lst()-rst())">&emsp;
    <input type="button" value="*" onclick="ans(lst()*rst())">&emsp;
    <input type="button" value="/" onclick="ans(rst()?lst()/rst():'除数不得为零')"><br>
    <label for="ans">计算结果</label> <input id="ans" type="text" readonly><br>
</body>

</html>
    

JunDao

359 Words

2020-04-09 17:08 +0800