08-js写计算器

image.png
<html>
    <head>
        <title>计算器</title>
        <meta charset="UTF-8"/>
        <style type="text/css">
            #shoudiv{
                border:solid 1px;
                width:320px;
                height:400px;
                border-radius: 10px;
                text-align: center;
                margin: auto;
                margin-top: 60px;
                background-color: floralwhite;
            }
            input[type=text]{
                margin-top: 20px;
                width:290px;
                height:40px;
                font-size: 20px;
                
            }
            input[type=button]{
                width:60px;
                height:60px;
                margin-top: 20px;
                margin-left:5px;
                margin-right:5px;
                font-size: 20px;
                font-weight: bold;
                font-family:"微软雅黑" ;
            }
            
            
        </style>
        
         <script type="text/javascript">
            function test(btn){
                var num=btn.value;
                
                
                switch(num){
                    case"=": document.getElementById("inp").value=eval(document.getElementById("inp").value);break;
                    case"c": document.getElementById("inp").value="";break;
                    default:document.getElementById("inp").value=document.getElementById("inp").value+num;
                    
                }
            }
            
            
            
         </script>
    </head>
    <body>
        <h1 align="center" >Mu_Zhou </h1>
        <hr />
        <div id="shoudiv">
            <input type="text" name="" id="inp" value="" />
            <input type="button" name="" id="" value="1" onclick="test(this)"/>
            <input type="button" name="" id="" value="2" onclick="test(this)"/>
            <input type="button" name="" id="" value="3" onclick="test(this)"/>
            <input type="button" name="" id="" value="4" onclick="test(this)"/><br />
            <input type="button" name="" id="" value="5" onclick="test(this)"/>
            <input type="button" name="" id="" value="6" onclick="test(this)"/>
            <input type="button" name="" id="" value="7" onclick="test(this)"/>
            <input type="button" name="" id="" value="8" onclick="test(this)"/><br />
            <input type="button" name="" id="" value="9" onclick="test(this)"/>
            <input type="button" name="" id="" value="0" onclick="test(this)"/>
            <input type="button" name="" id="" value="+" onclick="test(this)"/>
            <input type="button" name="" id="" value="-" onclick="test(this)"/><br />
            <input type="button" name="" id="" value="*" onclick="test(this)"/>
            <input type="button" name="" id="" value="/" onclick="test(this)"/>
            <input type="button" name="" id="" value="c" onclick="test(this)"/>
            <input type="button" name="" id="" value="=" onclick="test(this)"/>
            
            
        </div>
    </body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容