0

这是我的javascript代码

for (var i = 1; i <= _MAXPAGECOUNT - 2; i++) {

        e = document.getElementsByName("q" + i + "[]");
        for (var j = 0; j <= e.length - 1; j++) {
            if (e[j].checked) {
                result = result + "," + i + ":" +  e[j].value;

               // break;
            }
        }}

问题是这样的,它 在代码中显示这样的结果1:2,1:3,1:4,2:3,2:4,2:5i表示问题编号和j答案编号,但我希望结果为像这样1:2,3,4 ; 2:3,4,5

4

1 回答 1

0

尝试这个

for (var i = 1; i <= _MAXPAGECOUNT - 2; i++) {
        result = result+i+":";
        e = document.getElementsByName("q" + i + "[]");
        for (var j = 0; j <= e.length - 1; j++) {
            if (e[j].checked) {
                result = result + e[j].value;
               // break;
            }
        }
        if(i<_MAXPAGECOUNT - 2)
        {
             result = result+" ; ";
        }
}
于 2012-05-11T08:10:05.510 回答