web實現簡單計算器

<html>
<head><title>簡單計算器</title>
<style>
.b1{
width:50px;
height:35px;
margin-top:10px;
background-color:#99FFFF;
}
.screen{
    width:215px;
    height:35px;
    text-align: right;
    padding-right:10px;
    font-size:20px;
    background-color:#99FFFF;
}
html{
    padding:150px 550px  100px 550px; 
    background-color:lightgrey;
}
</style>
<script>
function jsj(num){
document.getElementById("result").value+=document.getElementById(num).value;
}
function eva() {
            //計算輸入結果
            document.getElementById("result").value = eval(document.getElementById("result").value);
}
function tuiGe() {
    //退格
    var arr = document.getElementById("result");
    arr.value = arr.value.substring(0, arr.value.length - 1);
}
</script>
</head>
<body>
<div id="screen"><input type="text" name="result" id="result" class="screen" placeholder="請輸入計算公式"/></div>
<!-- <div id="buttonArea"> -->
<div>
<input type="button" name="b1" value="1" id="1" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b2" value="2" id="2" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b3" value="3" id="3" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="//" value="/" id="/" class="b1" οnclick="jsj(this.id)"/><br/>
</div>
<div>
<input type="button" name="b4" value="4" id="4" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b5" value="5" id="5" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b6" value="6" id="6" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name=".." value="." id="." class="b1" οnclick="jsj(this.id)"/><br/>
</div>
<div>
<input type="button" name="b7" value="7" id="7" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b8" value="8" id="8" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="b9" value="9" id="9" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="plus" value="刪除" id="/" class="b1" οnclick="tuiGe()"/><br/>
</div>
<div>
<input type="button" name="plus" value="+" id="+" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="plus" value="-" id="-" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="plus" value="*" id="*" class="b1" οnclick="jsj(this.id)"/>
<input type="button" name="total" value="=" id="t" class="b1" οnclick="eva()"/>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章