将文本框中的数字拆分为 4 组数字,每组数字得到其总和,并将每组每个总和的所有最后数字组合在一起



<html>
<title> Test </title>
<body>
<b>Paste Here (ctrl+v)</b>
<br>
<input id="boxx1" type="text" style="width:210px;" onKeyPress="boxx1KeyPress()" onKeyUp="boxx1KeyPress()">
<br>
<input type="button" Value="Clear Field" onClick="ClearField()">
<br>
<br>
<b>Output 1</b> <input id="boxx2" type="text" style="width:370px;" readonly> <b>Comp 1</b><input id="comp1" type="text" style="width:180px;" readonly>
<br>
<br>
<b>Output 2</b> <input id="boxx3" type="text" style="width:370px;" readonly> <b>Comp 2</b><input id="comp2" type="text" style="width:180px;" readonly>
</body>
<script>
function boxx1KeyPress() {
var boxx1 = document.getElementById("boxx1");
var s = boxx1.value.replace(/[ ,]+/g, ",");
var x = s;
var lblValue = document.getElementById("boxx2");
lblValue.value = "" + s;
var points = lblValue.value.split(",");
document.getElementById("boxx3").value = points.sort().join();
var comp1 = document.getElementById("boxx2");
var res = comp1.value.split(",", 4);
document.getElementById("comp1").value = res;
var comp2 = document.getElementById("boxx3");
var res2 = comp2.value.split(",", 4);
document.getElementById("comp2").value = res2;
}
function ClearField() {
document.getElementById("boxx1").value = "";
document.getElementById("boxx2").value = "";
document.getElementById("boxx3").value = "";
document.getElementById("comp1").value = "";
document.getElementById("comp2").value = "";
}
</script>
</html>

嗨,我需要你们的帮助。

我迷路了,不知道下一步该怎么做。 提前非常感谢那些可以帮助我的人。

到目前为止我做了什么:

我从如下所示的来源获得一组数字:

来源: 22 21 65 1 23 54 65 13 11 32 99 65 43 44 55 3 4 5 88 99

输出 1 结果:22,21,65,1,23,54,65,13,11,32,99,65,43,44,55,3,4,5,88,99

Comp1 结果:"这就是我需要的">

输出 2 结果:1,11,13,21,22,23,3,32,4,43,44,5,54,55,65,65,65,65,88,99,99

Comp2 结果:"这就是我需要的">

这是一个 20 个集合数字,一旦将此数字粘贴到"粘贴到此处"文本框中,就会以空格作为分隔符 逗号将替换空格,并在输出文本框中显示结果,在第二个输出文本框中,同样的事情会发生,但按升序排列。

我想做什么:

从 Output1 和 Output2 上显示的数字中,我需要将这些数字组分成 5 个,每个组有 4 组数字,并找到每个组的总和如下所示:

22,21,65,1 等于 109

23,54,65,13 等于 155

11,32,99,65 等于 207

43,44,55,3 等于 145

4,5,88,99 等于 196

现在我需要获取每个结果的所有最后一位数字,组合的数字应该显示在 Comp 1 文本框中,它应该看起来像这样:

95756

在 Comp 2 文本框上,基础将是"输出 2"文本框。

希望对您有所帮助

<html>
<title> Test </title>
<body>
<b>Paste Here (ctrl+v)</b>
<br>
<input id="boxx1" type="text" style="width:210px;">
<br>
<input type="button" Value="Add" onClick="go()">
<input type="button" Value="Clear Field" onClick="ClearField()">
<br>
<br>
<b>Output 1</b> <input id="boxx2" type="text" style="width:370px;" readonly> <b>Comp 1</b><input id="comp1" type="text" style="width:180px;" readonly>
<br>
<br>
<b>Output 2</b> <input id="boxx3" type="text" style="width:370px;" readonly> <b>Comp 2</b><input id="comp2" type="text" style="width:180px;" readonly>
</body>
<script>
function go() {
var boxx1 = document.getElementById("boxx1");
var s = boxx1.value.replace(/ /g, ",");
var lblValue = document.getElementById("boxx2");
lblValue.value = s;
var points = s.split(",");
var comp1 = '';
for (var i = 0; i < points.length; i += 4) {
var sum = 0;
for (var j = i; j < i + 4; j++) {
sum += Number(points[j]);
}
comp1 += (sum % 10);
}
document.getElementById("comp1").value = comp1;
var comp2 = '';
document.getElementById("boxx3").value = points.sort().join();
for (var i = 0; i < points.length; i += 4) {
var sum = 0;
for (var j = i; j < i + 4; j++) {
sum += Number(points[j]);
}
comp2 += (sum % 10);
}
document.getElementById("comp2").value = comp2;
}
function ClearField() {
document.getElementById("boxx1").value = "";
document.getElementById("boxx2").value = "";
document.getElementById("boxx3").value = "";
document.getElementById("comp1").value = "";
document.getElementById("comp2").value = "";
}
</script>
</html>

最新更新