




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、簡單的計算器簡單的計算器Javascript代碼var num=0,result=0,numshow=0; var operate=0; /判斷輸入狀態(tài)的標(biāo)志 var calcul=0; /判斷計算狀態(tài)的標(biāo)志 var quit=0; /防止重復(fù)按鍵的標(biāo)志 function command(num) var str=String(document.calculator.numScreen.value); /獲得當(dāng)前顯示數(shù)據(jù) str=(str!=0) ? (operate=0) ? str : ) : ; /如果當(dāng)前值不是0,且狀態(tài)為0,則返回當(dāng)前值,否則返回空值; str=str + Strin
2、g(num); /給當(dāng)前值追加字符 document.calculator.numScreen.value=str; /刷新顯示 operate=0; /重置輸入狀態(tài) quit=0; /重置防止重復(fù)按鍵的標(biāo)志 function dzero() var str=String(document.calculator.numScreen.value); str=(str!=0) ? (operate=0) ? str + 00 : 0) : 0; /如果當(dāng)前值不是0,且狀態(tài)為0,則返回當(dāng)str+00,否則返回0; document.calculator.numScreen.value=str; op
3、erate=0; function dot() var str=String(document.calculator.numScreen.value); str=(str!=0) ? (operate=0) ? str : 0) : 0; /如果當(dāng)前值不是0,且狀態(tài)為0,則返回當(dāng)前值,否則返回0; for(i=0; i=str.length;i+) /判斷是否已經(jīng)有一個點號 if(str.substr(i,1)=.) return false; /如果有則不再插入 str=str + .; document.calculator.numScreen.value=str; operate=0;
4、function del() /退格 var str=String(document.calculator.numScreen.value); str=(str!=0) ? str : ; str=str.substr(0,str.length-1); str=(str!=) ? str : 0; document.calculator.numScreen.value=str; function clearscreen() /清除數(shù)據(jù) num=0; result=0; numshow=0; document.calculator.numScreen.value=0; function plus
5、() /加法 calculate(); /調(diào)用計算函數(shù) operate=1; /更改輸入狀態(tài) calcul=1; /更改計算狀態(tài)為加 function minus() /減法 calculate(); operate=1; calcul=2; function times() /乘法 calculate(); operate=1; calcul=3; function divide() /除法 calculate(); operate=1; calcul=4; function persent() /求余 calculate(); operate=1; calcul=5; function e
6、qual() calculate(); /等于 operate=1; num=0; result=0; numshow=0; / function calculate() numshow=Number(document.calculator.numScreen.value); if(num!=0 & quit!=1) /判斷前一個運算數(shù)是否為零以及防重復(fù)按鍵的狀態(tài) switch(calcul) /判斷要輸入狀態(tài) case 1:result=num+numshow;break; /計算+ case 2:result=num-numshow;break; /計算- case 3:resul
7、t=num*numshow;break; case 4:if(numshow!=0)result=num/numshow;elsedocument.getElementById(note).innerHTML=被除數(shù)不能為零!; setTimeout(clearnote,4000) break; case 5:result=num%numshow;break; quit=1; /避免重復(fù)按鍵 else result=numshow; numshow=String(result); document.calculator.numScreen.value=numshow; num=result;
8、/存儲當(dāng)前值 function clearnote() /清空提示 document.getElementById(note).innerHTML=; Html代碼 寫給新手:js表單操作(四) 簡單計算器(二) body font-size:12px; font-family:Arial, Georgia, Times New Roman, Times, serif; color:#555; text-align:center; background-color:#e2e2e2; h6 margin:0; font-size:12px; #calculator width:240px; he
9、ight:auto; overflow:hidden; margin:10px auto; border:#fff 1px solid; padding-bottom:10px; background-color:#f2f2f2; #calculator div clear:both; #calculator ul padding:0; margin:5px 14px; border:#fff 1px solid; height:auto; overflow:hidden #calculator li list-style:none; float:left; width:32px; heigh
10、t:32px; margin:5px; display:inline; line-height:32px; font-size:14px; background-color:#eaeaea; #calculator li.tool background-color:#e2e2e2; #calculator li:hover background-color:#f9f9f9; cursor:pointer; #calculator li:active background-color:#fc0; cursor:pointer; #calculator li.tool:active backgro
11、und-color:#d8e8ff; cursor:pointer; #calcu-head text-align:left; padding:10px 15px 5px; span.imyeah float:right; color:#ccc; span.imyeah a color:#ccc; .screen width:200px; height:24px; line-height:24px; padding:4px; border:#e6e6e6 1px solid; border-bottom:#f2f2f2 1px solid; border-right:#f2f2f2 1px s
12、olid; margin:10px auto; direction:ltr; text-align:right; font-size:16px; color:#999; #calcu-foot text-align:left; padding:10px 15px 5px; height:auto; overflow:hidden; span#note float:left; width:210px; height:auto; overflow:hidden; color:red; span.welcome clear:both; color:#999; span.welcome a float
13、:right; color:#999; /此處插入上面的js代碼 Im Yeah!簡單的計算器 7 8 9 C 4 5 6 1 2 3 + - 0 00 . % = 歡迎使用javascript計算器!反饋 HTML 簡單的計算器 walker 歡迎使用JavaScript計算器 反饋 CSS /*Basic reset*/* margin:0; padding:0; box-sizing: border-box; font: 14px Arial,sans-serif;html height:100%; background-color:lightslategrey;#calculator
14、margin: 15px auto; width:330px; height:400px; border: 1px solid lightgray; background-color:darkgrey; padding:15px;/*LOGO*/.LOGO height:20px;.LOGO .name float:left; line-height:30px;.LOGO .verson float:right; line-height:30px;/*screen*/#shuRu margin-top:15px;.screen margin-top:5px; width:300px; heig
15、ht:40px; text-align: right; padding-right:10px; font-size:20px;#keys border:1px solid lightgray; height:223px; margin-top:25px; padding:8px;#keys .last margin-right:0px;.footer margin-top:20px; height:20px;.footer .link float:right;#keys .buttons float:left; width: 42px; height: 36px; text-align:cen
16、ter; background-color:lightgray; margin: 0 17px 20px 0; Javascript var num = 0; / 定義第一個輸入的數(shù)據(jù) function jsq(num) /獲取當(dāng)前輸入 if(num=%) document.getElementById(screenName).value=Math.round(document.getElementById(screenName).value)/100; else document.getElementById(screenName).value += document.getElementById(num).value; function eva() /計算輸入結(jié)果 document.getElementById(screenName).value = eval(document.getElementById(screenN
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 華南農(nóng)業(yè)大學(xué)《德語會話(3)》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年素描人物考試試題及答案
- 2025年電機維修面試題及答案
- 2025年濟寧素描考試試題及答案
- 2025年江蘇質(zhì)檢員試題及答案
- 2025年院感培訓(xùn)考試試題及答案
- 2025年草房子測試題及閱讀答案
- 2025年財政學(xué)試題及答案 陳共
- 2025年高考語文備考之名著閱讀《鄉(xiāng)土中國》第六章《家族》內(nèi)容概述及跟蹤訓(xùn)練(含答案)
- 2025年旅游資源章節(jié)試題及答案
- 農(nóng)村宅基地買賣合同的標(biāo)準(zhǔn)版該如何寫5篇
- 2025山西國際能源集團社會招聘258人筆試參考題庫附帶答案詳解
- 普華永道中天會計師事務(wù)所-人工智能機遇在汽車領(lǐng)域
- 2025年安徽中醫(yī)藥高等??茖W(xué)校單招職業(yè)適應(yīng)性測試題庫及參考答案
- 湖北省武漢市2024-2025學(xué)年高三2月調(diào)研考試英語試題含答案
- 2025年皖西衛(wèi)生職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫新版
- GB/T 45222-2025食品安全事故應(yīng)急演練要求
- 深靜脈的穿刺術(shù)課件
- 2025年湖南高速鐵路職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫附答案
- 腰椎穿刺的護理
- 2025屆高考英語二輪復(fù)習(xí)備考策略課件
評論
0/150
提交評論