這篇文章主要為大家詳細(xì)介紹了javascript制作計算器的方法,文章中的示例代碼非常詳細(xì),若有興趣可以學(xué)習(xí)參考,閑言少敘直接上代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JS計算器</title>
<style>
body,p,input{
margin: 0;
padding: 0;
}
.wp{
width: 500px;
height: 500px;
border:10px solid black;
margin: 0 auto;
margin-top: 100px;
}
#text{
width: 480px;
height: 90px;
border-bottom: 10px solid black;
font-size: 50px;
line-height: 100px;
text-align: left;
padding-left: 20px;
background: #ffffff;
}
input{
width: 125px;
height: 100px;
background: #c0c0c0;
float: left;
font-size: 40px;
line-height: 100px;
text-align: center;
}
</style>
<script>
window.onload = function () {
var oText = document.getElementById('text');
var aBtn = document.getElementsByTagName('input');
var aText = oText.value
for(i=0;i<aBtn.length;i++){
aBtn[i].onclick = conunt;
};
function conunt(value){
if(this.value == 'C'){
oText.value ='';
}else if(this.value == '='){
oText.value = eval(oText.value)
}else if(this.value == 'x'){
oText.value -= oText.value.substring( oText.value.length);
}
else{
oText.value += this.value;
};
};
};
</script>
</head>
<body>
<div class="wp">
<input type="text" id="text">
<input type="button" id="btn1" value="C" >
<input type="button" id="btn2" value="/">
<input type="button" id="btn3" value="*">
<input type="button" id="btn4" value="-">
<input type="button" id="btn5" value="1">
<input type="button" id="btn6" value="2">
<input type="button" id="btn7" value="3">
<input type="button" id="btn8" value="+">
<input type="button" id="btn9" value="4">
<input type="button" id="btn10" value="5">
<input type="button" id="btn11" value="6">
<input type="button" id="btn12" value=".">
<input type="button" id="btn13" value="7">
<input type="button" id="btn14" value="8">
<input type="button" id="btn15" value="9">
<input type="button" id="btn16" value="=">
</div>
</body>
</html>
以上就是javascript制作計算器的詳細(xì)內(nèi)容,代碼示例簡單明了,如果在日常工作遇到此問題。通過這篇文章,希望你能有所收獲,更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文標(biāo)題:javascript制作計算器-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://aaarwkj.com/article2/doheic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、App開發(fā)、服務(wù)器托管、搜索引擎優(yōu)化、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容