1

JAVASCRIPT

 for (var i = 0; i < surveyResults.resultsOfSurvey.length; i = i + 1) {
                        debugger;

                        var answer = surveyResults.resultsOfSurvey[i].correct;
                        var qId = surveyResults.resultsOfSurvey[i].id;
                        var newElement = document.createElement('div');
                        newElement.id = surveyResults[i];
                        newElement.className = "answer";
                        newElement.innerHTML = "Antwort ist: " + answer + "! Fragen ID ist: " + qId + ".";
                        document.body.appendChild(newElement);

                    }

HTML

<div id="contentForSurvey">

        <div id="answers"></div>

如何将循环中的 div 插入for到 div 中id="answers"

4

1 回答 1

6

怎么样:

document.getElementById("answers").appendChild(newElement);

代替document.body.appendChild(newElement);

于 2013-09-27T14:51:00.697 回答