最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

HTML實現(xiàn)簡單計算器附詳細思路

  發(fā)布時間:2014-09-03 17:33:03   作者:佚名   我要評論
大概思路就是將按鍵內容以字符串形式存儲在文字框中當按鈕為“=”時,調用eval方法計算結果然后將結果輸出文字框中,需要的朋友可以參考下

復制代碼
代碼如下:

<!DOCTYPE html>
<html>
<meta name="content-type" content="text/html; charset=UTF-8">
<head>
<title>Calculator</title>
<!--將按鍵內容以字符串形式存儲在文字框中當按鈕為“=”時,調用eval方法計算結果然后將結果輸出文字框中-->
<script type="text/javascript">
var numresult;
var str;
function onclicknum(nums) {
str = document.getElementById("nummessege");
str.value = str.value + nums;
}
function onclickclear() {
str = document.getElementById("nummessege");
str.value = "";
}
function onclickresult() {
str = document.getElementById("nummessege");
numresult = eval(str.value);
str.value = numresult;
}
</script>
</head>
<body bgcolor="affff" >
<!--定義按鍵表格,每個按鍵對應一個事件觸發(fā)-->
<table border="1" align="center" bgColor="#bbff77"
style="height: 350px; width: 270px">
<tr>
<td colspan="4">
<input type="text" id="nummessege"
style="height: 90px; width: 350px; font-size: 50px" />
</td>
</tr>
<tr>
<td>
<input type="button" value="1" id="1" onclick="onclicknum(1)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="2" id="2" onclick="onclicknum(2)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="3" id="3" onclick="onclicknum(3)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="+" id="add" onclick="onclicknum('+')"
style="height: 70px; width: 90px; font-size: 35px">
</td>
</tr>
<tr>
<td>
<input type="button" value="4" id="4" onclick="onclicknum(4)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="5" id="5" onclick="onclicknum(5)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="6" id="6" onclick="onclicknum(6)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="-" id="sub" onclick="onclicknum('-')"
style="height: 70px; width: 90px; font-size: 35px">
</td>
</tr>
<tr>
<td>
<input type="button" value="7" id="7" onclick="onclicknum(7)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="8" id="8" onclick="onclicknum(8)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="9" id="9" onclick="onclicknum(9)"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="*" id="mul" onclick="onclicknum('*')"
style="height: 70px; width: 90px; font-size: 35px">
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="0" id="0" onclick="onclicknum(0)"
style="height: 70px; width: 190px; font-size: 35px">
</td>
<td>
<input type="button" value="." id="point" onclick="onclicknum('.')"
style="height: 70px; width: 90px; font-size: 35px">
</td>
<td>
<input type="button" value="/" id="division"
onclick="onclicknum('/')"
style="height: 70px; width: 90px; font-size: 35px">
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Del" id="clear"
onclick="onclickclear()"
style="height: 70px; width: 190px; font-size: 35px" />
</td>
<td colspan="2">
<input type="button" value="=" id="result"
onclick="onclickresult()"
style="height: 70px; width: 190px; font-size: 35px" />
</td>

</tr>

</table>
</body>
</html>

相關文章

  • HTML img標簽和超鏈接標簽詳細介紹

    文章介紹了HTML中img標簽的使用,包括src屬性(指定圖片路徑)、相對/絕對路徑區(qū)別、alt替代文本、title提示、寬高控制及邊框設置等,本文主要給大家介紹HTML img標簽和超鏈
    2025-06-20
  • HTML中meta標簽的常見使用案例(示例詳解)

    HTML meta標簽用于提供文檔元數據,涵蓋字符編碼、SEO優(yōu)化、社交媒體集成、移動設備適配、瀏覽器控制及安全隱私設置,優(yōu)化頁面顯示與搜索引擎索引,本文給大家介紹HTML中meta
    2025-06-20
  • HTML input 標簽示例詳解

    input 標簽主要用于接收用戶的輸入,隨 type 屬性值的不同,變換其具體功能,本文通過實例圖文并茂的形式給大家介紹HTML input 標簽,感興趣的朋友一起看看吧
    2025-06-20
  • html 滾動條滾動過快會留下邊框線的解決方案

    這篇文章主要介紹了html 滾動條滾動過快會留下邊框線的解決方案,解決方法很簡單,可以將 dialog 單獨拿出來別放在 transform 的子元素里,需要的朋友可以參考下
    2025-06-09
  • 在 HTML 文件中添加圖片的常用方法

    本文將介紹如何使用<img>標簽在 HTML 中添加圖片,并展示一些常見的用法和技巧,通過本文的介紹,應該掌握了在 HTML 中添加和調整圖片的基礎知識,感興趣的朋友一起看
    2025-05-16
  • HTML 表格詳解(簡單易懂較詳細)

    HTML表格用于在網頁上展示數據,通過標簽及其相關標簽來創(chuàng)建,表格由行和列組成,每一行包含一個或多個單元格,單元格可以包含文本、圖像、鏈接等元素,本文將詳細介紹HTML表格
    2025-03-12
  • 禁止HTML頁面滾動的操作方法

    本文介紹了三種禁止HTML頁面滾動的方法:通過CSS的overflow屬性、使用JavaScript的滾動事件監(jiān)聽器以及使用CSS的position:fixed屬性,每種方法都有其適用場景和優(yōu)缺點,感興
    2025-02-24
  • 使用HTML和CSS實現(xiàn)文字鏤空效果的代碼示例

    在 Web 開發(fā)中,文本的視覺效果是提升用戶體驗的重要因素之一,通過 CSS 技巧,我們可以創(chuàng)造出許多獨特的效果,例如文字鏤空效果,本文將帶你一步一步實現(xiàn)一個簡單的文字鏤空
    2024-11-17
  • Html去除a標簽的默認樣式的操作代碼

    在Html中,a標簽默認的超鏈接樣式是藍色字體配下劃線,這可能不滿足所有設計需求,如需去除這些默認樣式,可以通過CSS來實現(xiàn),本文給大家介紹Html去除a標簽的默認樣式的操作代碼
    2024-09-25
  • HTML文本域如何設置為禁止用戶手動拖動

    在HTML中,可以通過設置CSS的resize屬性為none,來禁止用戶手動拖動文本域(textarea)的大小,這種方法簡單有效,適用于大多數現(xiàn)代瀏覽器,但需要在老舊瀏覽器中進行測試以確保
    2024-09-25

最新評論

开远市| 张掖市| 济阳县| 平罗县| 岳阳市| 嘉黎县| 留坝县| 喀喇| 新疆| 丰顺县| 故城县| 两当县| 南和县| 天镇县| 阿拉尔市| 从化市| 治县。| 开原市| 买车| 八宿县| 曲水县| 文安县| 封开县| 舒兰市| 大邑县| 广灵县| 上栗县| 昌江| 太和县| 灵石县| 丹巴县| 当涂县| 屯门区| 会理县| 高碑店市| 惠东县| 清涧县| 五台县| 吉首市| 团风县| 毕节市|