简体   繁体   English

有42个HTML元素需要放置在3个数组中。 Java脚本

[英]Have 42 HTML Elements that need to be placed in 3 arrays. Javascript

Kind of a noob question, but I have a page with 42 checkboxes all placed into an array, but I need to split the array into 3 smaller arrays. 有点菜鸟问题,但我有一个页面,其中包含42个复选框,所有复选框均置于一个数组中,但是我需要将该数组拆分为3个较小的数组。

array(0) = smallOne(0);
array(1) = smallTwo(0);
array(2) = smallThree(0)
array(3) = smallOne(1);
array(4) = smallTwo(1);
array(5) = smallThree(1);

And so forth. 依此类推。 Is there a method that does this or will I just need to list them all out? 有没有这样做的方法,或者我只需要将它们全部列出来?

Here's the javascript so far: 到目前为止,这是JavaScript:

function SendForm() {
    var elLength = form1.elements.length;
    var chk = new Array(42);
    var desc = new Array(14);
    var local = new Array(14);
    var other = new Array(14);
    for (i = 0; i < elLength; i++) {
        var count = 0;
        var type = form1.elements[i].type;
        if (type == "checkbox") {
            if (form1.elements[i].checked) {
                chk(count) = true;
            }
            else {
               chk(count) = false;
            }
            count++;
        }
        else {
        }       
    }
}

You could do something like this to assign them: 您可以执行以下操作来分配它们:

for (var i = 0; i < 14; i++)
{
    var x = i * 3;
    desc[i] = chk[x];
    local[i] = chk[x + 1];
    other[i] = chk[x + 2];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM