css 数字平铺布局

效果图

复制代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>活动中心</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
            border: none;
            width: 100%;
        }

        body {
            background-color: #F6FBF7;
        }

        .textinput {
            padding: 10px;
            border: solid 1px #e5e5e5;
            border-radius: 5px;
        }

        .container {
            border-radius: 5px;
            border: solid 1px #ECECEC;
            font-weight: bold;
            background-color: white;
            text-align: left; /* 确保文本居左 */
            margin: 20px auto;
            width: 90%;
            padding: 10px;
            display: flex;
            flex-wrap: wrap;
            gap: 10px; /* 调整子元素之间的间距 */
        }

        .number {
            background-color: #f0f0f0;
            padding: 10px 20px;
            border-radius: 5px;
            width: calc((100% / 4) - 48px); /* 每行4个,减去间距 */
            text-align: center;
        }
    </style>
</head>
<body>
    <div style="border: solid 1px #ECECEC;font-weight:bold;background-color:white;line-height:50px;text-align:center;margin:0px auto;width:100%;">随机数</div>

    <div style="border-radius: 5px; border: solid 1px #ECECEC; font-weight: bold; background-color: white; text-align: center; margin: 20px auto; width: 90%; padding: 10px;">
        <div style="display:flex;justify-content:space-between;align-items:center;line-height:45px;">
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <div style="width: 100px;">最小值:</div>
                <input id="txt_min" type="text" class="textinput" />
            </div>
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <div style="width: 180px; ">最大值:</div>
                <input id="txt_max" type="text" class="textinput" />
            </div>
        </div>
        <div style="display: flex; justify-content: space-between; align-items: center; line-height: 45px;">
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <div style="width: 100px; ">个数:</div>
                <input id="txt_count" type="text" class="textinput" />
            </div>
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <div style="width:180px;">运行重复:</div>
                <div style="display: flex; justify-content:flex-start; align-items: center;">
                    是<input id="txt_repeat_yeas" name="txt_repeat" type="radio" />
                    否<input id="txt_repeat_no" name="txt_repeat" checked type="radio" />
                </div>
            </div>
        </div>
        <button id="btn_generate" style="margin-top: 10px; padding: 10px 20px; background-color: #007BFF; color: white; border: none; border-radius: 5px;">生成</button>
    </div>

    <div class="container">
        <!-- 这里将动态生成数字 -->
        <div class="number">暂无</div>
    </div>

    <script src="~/Content/ApiClound/Js/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn_generate').click(function () {
                var min = parseInt($('#txt_min').val(), 10);
                var max = parseInt($('#txt_max').val(), 10);
                var count = parseInt($('#txt_count').val(), 10);
                var allowRepeat = $('#txt_repeat_yeas').is(':checked');

                if (isNaN(min) || isNaN(max) || isNaN(count)) {
                    alert('请输入有效的数字');
                    return;
                }

                if (min > max) {
                    alert('最小值不能大于最大值');
                    return;
                }

                if (count > (max - min + 1) && !allowRepeat) {
                    alert('生成的个数不能大于区间范围');
                    return;
                }

                var numbers = [];
                while (numbers.length < count) {
                    var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
                    if (!allowRepeat && numbers.includes(randomNumber)) {
                        continue;
                    }
                    numbers.push(randomNumber);
                }

                $('.container').empty();
                numbers.forEach(function (number) {
                    $('.container').append('<div class="number">' + number + '</div>');
                });
            });
        });
    </script>
</body>
</html>
相关推荐
asdfg1258963几秒前
JS中的闭包应用
开发语言·前端·javascript
kirk_wang2 分钟前
Flutter 导航锁踩坑实录:从断言失败到类型转换异常
前端·javascript·flutter
静小谢1 小时前
前后台一起部署,vite配置笔记base\build
前端·javascript·笔记
用户47949283569151 小时前
改了CSS刷新没反应-你可能不懂HTTP缓存
前端·javascript·面试
还好还好不是吗1 小时前
老项目改造 vue-cli 2.6 升级 rsbuild 提升开发效率300% upupup!!!
前端·性能优化
sumAll2 小时前
别再手动对齐矩形了!这个开源神器让 AI 帮你画架构图 (Next-AI-Draw-IO 体验)
前端·人工智能·next.js
OpenTiny社区2 小时前
2025OpenTiny星光ShowTime!年度贡献者征集启动!
前端·vue.js·低代码
wangan0942 小时前
不带圆圈的二叉树
java·前端·javascript
狗哥哥2 小时前
从零到一:打造企业级 Vue 3 高性能表格组件的设计哲学与实践
前端·vue.js·架构
疯狂平头哥2 小时前
微信小程序真机预览-数字不等宽如何解决
前端