计算器

计算器大家都见过吧
html排版

    

再给他写个scss样式

*{
    padding: 0;
    margin: 0;
    outline: none;
    border: none;
}
.app{
    width: 600px;
    height: 400px;
    margin: 80px auto;
    &>input{
        width: 100%;
        height: 80px;
        background: gray;
        font-size: 30px;
    }
    .box{
        width: 100%;
        height: 100%;
        display: flex;
        .lbox{
            width: 80%;
            display: flex;
            flex-wrap: wrap;
            >input{
                width: 30%;
                border: 1px solid black;
                font-size: 30px;
            }
        }
        .rbox{
            width: 20%;
            height: 100%;
            display: flex;
            flex-direction: column;
            >input{
                width: 100%;
                height: 100px;
                border: 1px solid black;
                font-size: 30px;


            }
        }
    }
}

用js实现它的功能

var text =document.querySelector("input[type=text]");
var box =document.querySelector(".box")
var buts =document.querySelectorAll("input[type=button]");
var val =document.querySelector("#dd")
console.log(val)
var str =""
box.onclick =function(e){
    var e =e.event||window.event
    if(e.target.nodeName =="INPUT"){
       str += e.target.value
       text.value =str
    }
}
val.onclick =function(){
    text.value =eval(text.value)
}

你可能感兴趣的:(计算器)