文章阅读

沉浸阅读完整内容

写文章

计算2数累计之和

正在统计阅读人数 正在统计字数
登录收藏0
字号 100%

计算2数累计之和

代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            p {
                margin: 0 auto;
                height: 73px;
                width: 660px;
                background-color: seagreen;
                text-align: center;
            }

            input {
                outline: none;
                height: 50px;
                margin-top: 11px;
                border: 0;
                vertical-align: bottom;
            }

            button {
                height: 52px;
                width: 100px;

                border: 0;
            }
        </style>
    </head>
    <body>
        <!-- 输入两个数,计算2个数之间的整数之和 -->

        <p>
            <input type="text" name="" id="a" placeholder="请输入起始值">
            ~
            <input type="text" name="" id="b" placeholder="请输入目标值">
            <button onclick="js()">计算</button>
            <input type="text" name="" id="c">
        </p>
        <script>
            function js() {
                let A = parseInt(a.value);
                let B = parseInt(b.value);
                let sum = 0;

                if (A < B) {
                    for ( ; A <= B; A++) {

                        sum = sum + A;
                        document.getElementById("c").value = sum;
                    }
                } else {
                    document.getElementById("c").value = "参数错误";
                }
            }
        </script>
    </body>
</html>

推荐阅读

4 篇精选
文章 / 123uniapp调用微信支付功能 文章 / 124数组扁平化处理 文章 / 125Vue3组件如何进行值的传递 文章 / 126Vue3配置路由信息过程VueRouter

发表评论

评论 0

还没有评论,欢迎留下第一条讨论。

分享精彩,传递价值

生成专属海报,分享你的文章,让更多人发现好内容

浏览器不支持 Canvas,无法生成海报。

每日签到

每天来这里,记录一点持续积累。

当前积分--积分
本月签到--
本月获得--积分
正在读取