0

我有:

var answers = [];

                var frage1 = document.getElementById("frage1").innerHTML;
                frage1antwort1 = $('#frage1antwort1:checked').length; f.Example Value = 0
                frage1antwort2 = $('#frage1antwort2:checked').length; f.Example Value = 0
                frage1antwort3 = $('#frage1antwort3:checked').length; f.Example Value = 1

                var frage2 = document.getElementById("frage2").innerHTML;
                frage2antwort1 = $('#frage2antwort1:checked').length; f.Example Value = 0
                frage2antwort2 = $('#frage2antwort2:checked').length; f.Example Value = 0
                frage2antwort3 = $('#frage2antwort3:checked').length; f.Example Value = 1

                var frage3 = document.getElementById("frage3").innerHTML;
                frage3antwort1 = $('#frage3antwort1:checked').length; f.Example Value = 1
                frage3antwort2 = $('#frage3antwort2:checked').length; f.Example Value = 0
                frage3antwort3 = $('#frage3antwort3:checked').length; f.Example Value = 0

                var frage4 = document.getElementById("frage4").innerHTML;
                frage4antwort1 = $('#frage4antwort1:checked').length; f.Example Value = 0
                frage4antwort2 = $('#frage4antwort2:checked').length; f.Example Value = 1
                frage4antwort3 = $('#frage4antwort3:checked').length; f.Example Value = 0 

                var frage5 = document.getElementById("frage5").innerHTML;
                frage5antwort1 = $('#frage5antwort1:checked').length; f.Example Value = 0
                frage5antwort2 = $('#frage5antwort2:checked').length; f.Example Value = 1
                frage5antwort3 = $('#frage5antwort3:checked').length; f.Example Value = 0

我正在尝试构建一个包含问题的数组并为其选择答案。我没有什么是对的。结果[问题= 1,答案= 3],类似的东西。请帮忙!

4

1 回答 1

1

你为什么要尝试数组?你可以很容易地对对象做同样的事情。

请检查http://www.w3schools.com/js/js_objects.asp

例如

function question(que,ans1,ans2,ans3)
{
this.question=que;
this.answer1=ans1;
this.answer2=ans2;
this.answer3=ans3;
}

进而

var frage1=new question(document.getElementById("frage1").innerHTML, $('#frage1antwort1:checked').length,$('#frage1antwort2:checked').length,$('#frage1antwort3:checked').length);

您只需要定义问题对象,然后创建新对象或分配值并在需要时抓取。

这将使您清楚地了解使用对象

于 2013-09-26T12:28:45.897 回答