吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5611|回复: 64
收起左侧

[其他原创] 小学数学出题,网页版

[复制链接]
melodyy 发表于 2023-10-17 09:20
本帖最后由 melodyy 于 2023-10-24 09:56 编辑

几天前看到这个贴子,因为本家里没打印机,所有修改了一下用手机来玩还不错
有打印机的可以看看这原贴
https://www.52pojie.cn/forum.php?mod=viewthread&tid=1843105&highlight=%D0%A1%D1%A7
下面是我改后用手机玩的效果图
[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            margin: 0;
            padding: 0;
        }

        .header {
            position: fixed; /* 添加固定定位 */
            top: 0; /* 将标题固定在页面顶部 */
            left: 0;
            width: 100%;
            background-color: #4CAF50;
            color: white;
            text-align: center;
			padding: 5px 0;
        }

        .container {
            max-width: 800px;
            margin: 100px auto; /* 为产生滚动条留出空间 */
            background-color: #fff;
            padding: 50px 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .hidden {
            display: none;
        }

        #options {
            margin-bottom: 20px;
            line-height: 28px;
        }

        input {
            max-width: 50px;
        }

        label {
            margin-right: 10px;
        }

        #questions {
            margin-top: 20px;
        }

        .question {
            border: 1px solid #ccc;
            padding: 10px;
            max-width: 100%;
            margin-bottom: 10px;
            color: #000;
            display: flex;
            align-items: center;
        }

        .question p {
            font-size: 18px;
            line-height: 18px;
            margin-right: 10px;
        }

        .question .answer-container {
            display: flex;
            align-items: center;
        }

        .question .answer-container input[type="text"] {
            width: 50px;
            margin-left: 10px;
        }

        .question .answer-container .grade {
            display: inline-block;
            font-size: 20px;
            padding-left: 10px;
            vertical-align: middle;
        }


        .slider {
            width: 100%;
        }
    </style>
    <title>小学数学出题器</title>
</head>

<body>
    <div class="header">
        <h1>小学数学出题器</h1>
        <button>选项开关</button>
        <button>生成题目</button>
        <button>查看答案</button>
    </div>


    <div class="container">
        <div id="options" class="hidden">
            <label>运算符:</label>
            <input type="checkbox" id="addition" checked> 加法
            <input type="checkbox" id="subtraction" checked> 减法
            <input type="checkbox" id="multiplication" checked> 乘法
            <input type="checkbox" id="division" checked> 除法
            <br>
            <label>数字个数:</label>
            <input type="number" id="numDigits" value="2">
            <br>
            <label>允许小数:</label>
            <input type="checkbox" id="allowDecimal"> 是
            <br>
            <label>题目数量:</label>
            <input type="number" id="numQuestions" value="10">
            <br>
            <label>数字范围:</label>
            <input type="number" id="minRange" value="1">
            <span>-</span>
            <input type="number" id="maxRange" value="100">
            <br>
            <label>文字颜色:</label>
            <input type="color" id="textColor" value="#000000">
            <br>
            <label>字体大小:</label>
            <input type="range" class="slider" id="fontSizeSlider" min="12" max="24" step="2">
            <br>
        </div>
        <div id="questions" class="hidden"></div>
        <div style="position: relative; top: 10000px;"></div> <!-- 在最后添加一个足够长的空白元素,以便产生滚动条 -->
    </div>



    <script>
        // script.js
        function toggleOptions() {
            const content = document.getElementById("options");
            content.classList.toggle("hidden");
        }

        function generateQuestions() {
            const operators = getSelectedOperators();
            const numDigits = parseInt(document.getElementById("numDigits").value);
            const allowDecimal = document.getElementById("allowDecimal").checked;
            const numQuestions = parseInt(document.getElementById("numQuestions").value);
            const minRange = parseInt(document.getElementById("minRange").value);
            const maxRange = parseInt(document.getElementById("maxRange").value);
            const textColor = document.getElementById("textColor").value;
            const fontSize = document.getElementById("fontSizeSlider").value;

            const questionsContainer = document.getElementById("questions");
            questionsContainer.style.color = textColor;
            questionsContainer.innerHTML = "";

            for (let i = 0; i < numQuestions; i++) {
                const question = generateQuestion(
                    operators,
                    numDigits,
                    allowDecimal,
                    minRange,
                    maxRange
                );
                const questionElement = document.createElement("div");
                questionElement.className = "question";

                // 创建题目元素
                const questionTextElement = document.createElement("p");
                questionTextElement.textContent = `题${i + 1}:${question}`;
                questionTextElement.style.fontSize = fontSize + "px";

                // 创建填空输入框和评分元素的容器
                const answerContainer = document.createElement("div");
                answerContainer.className = "answer-container";

                const answerInput = document.createElement("input");
                answerInput.type = "text";
                answerInput.dataset.question = question;
                answerInput.style.fontSize = fontSize + "px";

                const gradeElement = document.createElement("span");
                gradeElement.className = "grade";
                gradeElement.style.fontSize = fontSize + "px";

                // 将题目元素和填空输入框添加到题目容器中
                answerContainer.appendChild(answerInput);
                answerContainer.appendChild(gradeElement);
                questionElement.appendChild(questionTextElement);
                questionElement.appendChild(answerContainer);

                // 将题目添加到题目容器中
                questionsContainer.appendChild(questionElement);
            }

            questionsContainer.classList.remove("hidden");
        }

        function getSelectedOperators() {
            const operators = [];
            if (document.getElementById("addition").checked) operators.push("+");
            if (document.getElementById("subtraction").checked) operators.push("-");
            if (document.getElementById("multiplication").checked) operators.push("*");
            if (document.getElementById("division").checked) operators.push("/");
            return operators;
        }

        function generateRandomNumber(min, max, allowDecimal) {
            const randomNumber = Math.random() * (max - min) + min;
            return allowDecimal ? randomNumber.toFixed(2) : Math.floor(randomNumber);
        }

        function generateQuestion(operators, numDigits, allowDecimal, minRange, maxRange) {
            const numbers = Array.from({ length: numDigits }, () =>
                generateRandomNumber(minRange, maxRange, allowDecimal)
            );
            const operatorArray = Array.from({ length: numDigits - 1 }, () =>
                operators[Math.floor(Math.random() * operators.length)]
            );

            let questionString = numbers[0].toString();
            for (let i = 1; i < numDigits; i++) {
                questionString += ` ${operatorArray[i - 1]} ${numbers[i]}`;
            }

            let result = eval(questionString);

            while (
                (!allowDecimal && (result % 1 !== 0 || result < 0)) ||
                result < 0
            ) {
                numbers.forEach((_, index) => {
                    numbers[index] = generateRandomNumber(
                        minRange,
                        maxRange,
                        allowDecimal
                    );
                });

                operatorArray.forEach((_, index) => {
                    operatorArray[index] =
                        operators[Math.floor(Math.random() * operators.length)];
                });

                questionString = numbers[0].toString();
                for (let i = 1; i < numDigits; i++) {
                    questionString += ` ${operatorArray[i - 1]} ${numbers[i]}`;
                }

                result = eval(questionString);
            }

            return questionString + " = ";
        }

        function gradeQuestions() {
            const questionsContainer = document.getElementById("questions");
            const questionElements = questionsContainer.getElementsByClassName(
                "question"
            );
            for (let i = 0; i < questionElements.length; i++) {
                const questionElement = questionElements[i];
                const answerInput = questionElement.querySelector(
                    "input[type='text']"
                );
                const gradeElement = questionElement.querySelector(".grade");
                gradeElement.innerHTML = "";
                if (answerInput.value === "") {
                    continue; // 跳过未填写答案的题目
                }
                const question = answerInput.dataset.question;
                const answer = eval(question.split("=")[0]);
                const userInput = parseFloat(answerInput.value);
                if (userInput === answer) {
                    gradeElement.innerText = "正确 ";
                    gradeElement.style.color = "green";
                } else {
                    gradeElement.innerText = "错误 ";
                    gradeElement.style.color = "red";
                }
                gradeElement.innerHTML += answer;
            }
        }

        function updateFontSize() {
            const fontSize = document.getElementById("fontSizeSlider").value;
            const questionElements = document.getElementsByClassName("question");
            for (let i = 0; i < questionElements.length; i++) {
                const questionElement = questionElements[i];
                const questionTextElement = questionElement.querySelector("p");
                const answerInput = questionElement.querySelector(
                    "input[type='text']"
                );
                const gradeElement = questionElement.querySelector(".grade");
                questionTextElement.style.fontSize = fontSize + "px";
                answerInput.style.fontSize = fontSize + "px";
                gradeElement.style.fontSize = fontSize + "px";
            }
        }
    </script>
</body>

</html> 



sx.rar (2.72 KB, 下载次数: 297)
动画1 (1).gif

免费评分

参与人数 14吾爱币 +18 热心值 +13 收起 理由
wuayi + 1 热心回复!
ZYDzzZ + 1 + 1 热心回复!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
kosglimmer + 1 谢谢@Thanks!
painstaking1 + 1 + 1 谢谢@Thanks!
ppzmdc + 1 + 1 热心回复!
kjwang1 + 1 + 1 热心回复!
alwapj + 1 + 1 谢谢@Thanks!
JZ2021 + 1 我很赞同!
chen29688 + 1 + 1 谢谢@Thanks!
无知灰灰 + 1 + 1 我很赞同!
xyz2000cn007 + 1 + 1 我很赞同!
一丝风 + 1 + 1 我很赞同!
woyucheng + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| melodyy 发表于 2023-10-17 14:33
bachelor66 发表于 2023-10-17 13:48
打开除了三个按钮,什么都没有,这是为什么呢?

选项开关点一下,选项被隐藏了
zcvsgy 发表于 2023-11-13 15:48
良有益 发表于 2023-10-18 11:46
小学数学出题器
        选项开关
        生成题目

<div class="header">
        <h1>小学数学出题器</h1>
        <button onclick="toggleOptions()">选项开关</button>
        <button onclick="generateQuestions()">生成题目</button>
        <button onclick="gradeQuestions()">查看答案</button>
    </div>
搞定!
良有益 发表于 2023-10-18 11:46
melodyy 发表于 2023-10-17 14:33
选项开关点一下,选项被隐藏了

    <div class="header">
        <h1>小学数学出题器</h1>
        <button>选项开关</button>
        <button>生成题目</button>
        <button>查看答案</button>
    </div>
代码里少了定位,所以没用,需要添加
odinchu 发表于 2023-10-17 09:26
牛逼,正好需要
SU150228 发表于 2023-10-17 09:33
来晚了!!!!!!!!!!!真可惜
haitao0514 发表于 2023-10-17 09:38
感谢分享,手机版更方便。
hjl198600 发表于 2023-10-17 09:42
支持一下,大佬太强了啊
wyeud 发表于 2023-10-17 09:45
小朋友们高兴坏了
gh12 发表于 2023-10-17 09:55
厉害&#128077;
yun520530 发表于 2023-10-17 10:04
小朋友们说我不服
tbyhx 发表于 2023-10-17 10:08
支持一下,大佬牛牪犇
shenxian321 发表于 2023-10-17 10:09
哈哈谢谢大佬可怕
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 19:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表