欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

JS實(shí)現(xiàn)基本的網(wǎng)頁(yè)計(jì)算器功能示例

本文實(shí)例講述了JS實(shí)現(xiàn)基本的網(wǎng)頁(yè)計(jì)算器功能。分享給大家供大家參考,具體如下:

創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司一直秉承“誠(chéng)信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!專注中小微企業(yè)官網(wǎng)定制,成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè),塑造企業(yè)網(wǎng)絡(luò)形象打造互聯(lián)網(wǎng)企業(yè)效應(yīng)。

<html>
    <head>
        <title>網(wǎng)頁(yè)計(jì)算機(jī)</title>
        <meta charset="UTF-8"/>
        <style type="text/css">
            #jsjdiv{
                border: solid 1px black;
                border-radius: 5px;
                width: 200px;
                /*height: 400px;*/
                text-align: center; /*設(shè)置div內(nèi)部居中*/
                margin: auto;    /*設(shè)置計(jì)算機(jī)居中*/
                background-color: darkgrey;
            }
            input[type=text]{
                width: 190px;          /*設(shè)置大小*/
                height: 35px;
                margin-top: 10px;   /*設(shè)置邊框*/
                margin-bottom: 5px;
            }
            input[type=button]{
                width: 44px;
                height: 44px;
                /*margin-left: 5px;
                margin-right: 5px;*/
                margin-top: 5px;
                margin-bottom: 10px;
                font-size: 25px;  /*設(shè)置text的字體大小及深度*/
                font-weight: 600;
            }
        </style>
        <script type="text/javascript">
            function cal(btn){
                var num=btn.value;
                switch (num){   // 利用eval可以把string的內(nèi)容轉(zhuǎn)化成代碼,在代碼中輸入可以直接進(jìn)行計(jì)算
                    case "=":
                        document.getElementById("inp").value=eval(document.getElementById("inp").value);
                        break;
                    case "c":
                        document.getElementById("inp").value="";
                        break;
                    default:        //進(jìn)行輸入數(shù)據(jù)的拼接
                        document.getElementById("inp").value=document.getElementById("inp").value + num;
                        break;
                }
            }
        </script>
    </head>
    <body>
        <div id="jsjdiv">
            <input type="text" name="" id="inp" value="" /><br />
            <input type="button" name="" id="btn" value="1" onclick="cal(this)"/>
            <input type="button" name="" id="" value="2" onclick="cal(this)"/>
            <input type="button" name="" id="" value="3" onclick="cal(this)"/>
            <input type="button" name="" id="" value="4" onclick="cal(this)"/><br />
            <input type="button" name="" id="" value="5" onclick="cal(this)"/>
            <input type="button" name="" id="" value="6" onclick="cal(this)"/>
            <input type="button" name="" id="" value="7" onclick="cal(this)"/>
            <input type="button" name="" id="" value="8" onclick="cal(this)"/><br />
            <input type="button" name="" id="" value="9" onclick="cal(this)"/>
            <input type="button" name="" id="" value="+" onclick="cal(this)"/>
            <input type="button" name="" id="" value="-" onclick="cal(this)"/>
            <input type="button" name="" id="" value="*" onclick="cal(this)"/><br />
            <input type="button" name="" id="" value="0" onclick="cal(this)"/>
            <input type="button" name="" id="" value="/" onclick="cal(this)"/>
            <input type="button" name="" id="" value="c" onclick="cal(this)"/>
            <input type="button" name="" id="" value="=" onclick="cal(this)" />
        </div>
    </body>
</html>

運(yùn)行效果:

JS實(shí)現(xiàn)基本的網(wǎng)頁(yè)計(jì)算器功能示例

網(wǎng)頁(yè)計(jì)算機(jī):

利用css進(jìn)行div的布局設(shè)置基本的計(jì)算機(jī)的基本的框架,

在其內(nèi)部設(shè)置text進(jìn)行顯示,利用button添加按鈕。

一個(gè)主要的點(diǎn):我們要在按按鈕的時(shí)候,把數(shù)據(jù)輸出到text文本上。我們利用了function添加一個(gè)函數(shù),在進(jìn)行按按鈕時(shí),利用onclick,連接到函數(shù),在函數(shù)中實(shí)現(xiàn)文本的顯示。但是我們?cè)诤瘮?shù)中只能對(duì)某個(gè)id進(jìn)行調(diào)用,這樣就表示有多少按鈕就要有多少函數(shù),而且內(nèi)容相同。所以我們引用了this(當(dāng)前對(duì)象)進(jìn)行調(diào)用。

另一方面,我們要實(shí)現(xiàn)計(jì)算,我們利用eval()把其中的內(nèi)容轉(zhuǎn)化為代碼,就相當(dāng)于代碼執(zhí)行。所以可以直接進(jìn)行運(yùn)算輸出。

當(dāng)我們輸入“=”和“c"就要進(jìn)行計(jì)算操作,相應(yīng)的我們利用了switch進(jìn)行區(qū)分。

感興趣的朋友可以使用在線HTML/CSS/JavaScript前端代碼調(diào)試運(yùn)行工具:http://tools.jb51.net/code/WebCodeRun測(cè)試上述代碼運(yùn)行效果。

PS:這里再為大家推薦幾款計(jì)算工具供大家進(jìn)一步參考借鑒:

在線一元函數(shù)(方程)求解計(jì)算工具:
http://tools.jb51.net/jisuanqi/equ_jisuanqi

科學(xué)計(jì)算器在線使用_高級(jí)計(jì)算器在線計(jì)算:
http://tools.jb51.net/jisuanqi/jsqkexue

在線計(jì)算器_標(biāo)準(zhǔn)計(jì)算器:
http://tools.jb51.net/jisuanqi/jsq

更多關(guān)于JavaScript相關(guān)內(nèi)容還可查看本站專題:《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript數(shù)組操作技巧總結(jié)》、《JavaScript事件相關(guān)操作與技巧大全》、《JavaScript操作DOM技巧總結(jié)》及《JavaScript字符與字符串操作技巧總結(jié)》

希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。

網(wǎng)站標(biāo)題:JS實(shí)現(xiàn)基本的網(wǎng)頁(yè)計(jì)算器功能示例
文章轉(zhuǎn)載:http://aaarwkj.com/article4/igidie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃外貿(mào)建站、域名注冊(cè)標(biāo)簽優(yōu)化、服務(wù)器托管網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
精品国产不卡在线观看| 天天操夜夜操夜夜操精品| 日本av免费观看一区二区| 欧美日韩亚洲视频一区久久| 亚洲黄色成人免费观看| 少妇的诱惑免费在线看| 久久国产亚洲欧美日韩精品| 亚洲三级伦理中文字幕| 熟女乱熟乱熟妇综合网二区| 亚洲精品色婷婷一区二区| 欧美日韩国产一区二区三区在线观看| 欧美劲爆三级免费观看| 最新日韩av一区二区| 成人国产av一区二区三区| 中文字幕日韩手机在线| 欧美日韩精品一区二区在线| 尤物在线观看视频播放| 在线观看国产自拍精品| 欧美香蕉视频播放二区| 精品久久人妻中文字幕免费| 热久久这里只有精品视频| 日韩欧美国产一区二区精品| 国产一区二区三区91精品| 日韩精品色av一区二区| 免费观看久久久激情片| 久久亚洲综合精品少妇| 最新日本人妻中文字幕| 国产黄色免费精品网站| 亚洲国产成人久久综合区| 亚洲熟妇av一区二区| 成人在线午夜免费视频| 丰满人妻大屁一区二区| 日韩不卡在线免费观看视频| 日韩精品一区二区三区高清| 岛国高清乱码中文字幕| 久久中文字幕av一区| 国产精品自拍国产精品| 特黄一级黄色大片免费看| 亚洲不卡免费在线视频| 91久久国产综合久久91| 91人妻精品丰满少妇区|