0

我如何用ajax上课?我有这个代码

function parseResponse(request){
if (request.readyState == 4){
    if (request.status == 200 || request.status == 304){
        var data = request.responseXML;

        var header1Name = data.getElementsByTagName('header1') [0].firstChild.nodeValue;
        var text1Name = data.getElementsByTagName('text1') [0].firstChild.nodeValue;

        var header1Elem = document.createElement("h3"); 
        var header1Text = document.createTextNode(header1Name);
        header1Elem.appendChild(header1Text);

        var text1Elem = document.createElement("p");
        var text1Text = document.createTextNode(text1Name);
        text1Elem.appendChild(text1Text);

        var existContent = document.getElementById("information");
        while ( existContent.hasChildNodes() ){
            existContent.removeChild(existContent.lastChild);
        }
        existContent.appendChild(header1Elem);
        existContent.appendChild(text1Elem);
    }
}

}

但我完全不知道如何上课,我想将课程附加到 h3 元素,非常感谢任何帮助,我的意思是类<h3 class="class">

4

1 回答 1

1

Use className property to set the class.

header1Elem.className = 'theclass';

Or setAttribute

header1Elem.setAttribute('class', 'theclass');
于 2013-03-31T23:38:32.240 回答