家有宝宝的家长,给小孩出练习题的利器,可以剩下一大笔费用。该软件来自吾爱论坛的热心网友haixiang1214。
<html> <head> <style> body { font-family: Arial, sans-serif; margin: 20px; } h1 { text-align: center; } .container { display: flex; flex-direction: column; align-items: center; } .options { display: flex; line-height: 25px; } .options label { display: block; } .questions { display: grid; gap: 20px; width: 80%; padding: 10px; } .question-item { font-size: 24px; font-weight: bold; text-align: left; } .print { margin-top: 20px; } .options div { margin-right: 20px; background-color: #8080801a; } </style> </head> <body> <h1>小学数学出题界面</h1> <div class="container"> <div class="options"> <div> <p>请选择运算符:</p> <label><input type="checkbox" id="add" checked> 加法</label> <label><input type="checkbox" id="sub"> 减法</label> <label><input type="checkbox" id="mul"> 乘法</label> <label><input type="checkbox" id="div"> 除法</label> </div> <div> <p>请选择出题数量:</p> <input type="number" id="num" min="1" max="10" value="5"> <button id="gen">生成题目</button> </div> <div> <p>请选择数字范围:</p> <label>最小值:<input type="number" id="min" min="1" max="9" value="1"></label> <label>最大值:<input type="number" id="max" min="2" max="10" value="10"></label> </div> <div> <p>设置题目列数:</p> <input type="number" id="columns" min="1" max="10" value="3"> </div> </div> <hr> <button class="print">打印题目</button> <div class="questions"></div> </div> <script> var add = document.getElementById("add"); var sub = document.getElementById("sub"); var mul = document.getElementById("mul"); var div = document.getElementById("div"); var num = document.getElementById("num"); var min = document.getElementById("min"); var max = document.getElementById("max"); var columns = document.getElementById("columns"); var gen = document.getElementById("gen"); var questions = document.getElementsByClassName("questions")[0]; var operators = ["+", "-", "×", "÷"]; var functions = [ function (a, b) { return a + b; }, function (a, b) { return a - b; }, function (a, b) { return a * b; }, function (a, b) { return a / b; } ]; function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function generateQuestions() { questions.innerHTML = ""; questions.style.gridTemplateColumns = `repeat(${columns.value}, 1fr)`; var selectedOperators = []; if (add.checked) selectedOperators.push(0); if (sub.checked) selectedOperators.push(1); if (mul.checked) selectedOperators.push(2); if (div.checked) selectedOperators.push(3); var questionNum = parseInt(num.value); var minValue = parseInt(min.value); var maxValue = parseInt(max.value); if (selectedOperators.length == 0) { alert("请至少选择一个运算符!"); return; } if (minValue >= maxValue) { alert("最小值应该小于最大值!"); return; } for (var i = 0; i < questionNum; i++) { var opIndex = randomInt(0, selectedOperators.length - 1); var op = operators[selectedOperators[opIndex]]; var func = functions[selectedOperators[opIndex]]; var a, b, result; do { a = randomInt(minValue, maxValue); b = randomInt(minValue, maxValue); result = func(a, b); } while (!Number.isInteger(result) || result <= 0); var questionItem = document.createElement("div"); questionItem.className = "question-item"; questionItem.textContent = a + " " + op + " " + b + " = "; questions.appendChild(questionItem); } } gen.addEventListener("click", generateQuestions); </script> </body> </html> 不懂代码的可以直接https://www.52pojie.cn/thread-1845482-1-1.html 去查看下载