在使用循环制作的div中附加书籍的描述,想要在引号中附加HTML代码而不是文本

时间:2018-03-07 15:34:33

标签: javascript html loops dom

我正在为这个大学课程的项目工作,我想知道如何将这些书的描述(下面提供的一个例子)作为一个段落附加到一个新创建的div作为HTML代码以引号开头和结尾的字符串。另请注意,我无法以任何方式,形状或形式操纵对象。

对象示例:

var itunesResponse = 

{
"results": [
{"fileSizeBytes":468847, "artistViewUrl":"https://itunes.apple.com/us/artist/brad-land/5526375?mt=11&uo=4", "trackCensoredName":"Goat", "trackViewUrl":"https://itunes.apple.com/us/book/goat/id420798692?mt=11&uo=4", "artworkUrl60":"http://is4.mzstatic.com/image/thumb/Publication18/v4/1c/48/62/1c4862bd-1a5d-0a7c-7143-2878aed682f8/source/60x60bb.jpg", "artworkUrl100":"http://is4.mzstatic.com/image/thumb/Publication18/v4/1c/48/62/1c4862bd-1a5d-0a7c-7143-2878aed682f8/source/100x100bb.jpg", "currency":"USD", "artistId":5526375, "artistName":"Brad Land", "genres":["Biographies & Memoirs", "Books", "Professional & Technical", "Education", "Nonfiction", "Social Science"], "kind":"ebook", "price":9.99, 
"description":"<b>Soon to be a major motion picture starring Nick Jonas, this&#xa0;searing memoir of fraternity culture and the perils of hazing&#xa0;provides an unprecedented window&#xa0;into the emotional landscape of young men.<\/b><br /><br />Reeling from a terrifying assault that has left him physically injured and psychologically shattered, nineteen-year-old Brad Land must also contend with unsympathetic local police, parents who can barely discuss “the incident” (as they call it), a brother riddled with guilt but unable to slow down enough for Brad to keep up, and the feeling that he’ll never be normal again.<br /><br />When Brad’s brother enrolls at Clemson University and pledges a fraternity, Brad believes he’s being left behind once and for all. Desperate to belong, he follows. What happens there—in the name of “brotherhood,” and with the supposed goal of forging a scholar and a gentleman from the raw materials of boyhood—involves torturous late-night hazing, heartbreaking estrangement from his brother, and, finally, the death of a fellow pledge. Ultimately, Brad must weigh total alienation from his newfound community against accepting a form of brutality he already knows too well.<br /><br /><i>From the Hardcover edition.<\/i>", "formattedPrice":"$9.99", "artistIds":[5526375], "genreIds":["9008", "38", "9029", "10037", "9002", "10120"], "releaseDate":"2004-02-03T08:00:00Z", "trackId":420798692, "trackName":"Goat", "userRatingCount":16, "averageUserRating":3.5}

这是我的循环:

let body = document.getElementById('wrapper');
        for(let i=0; i<itunesResponse.results.length; i++ ){
            let newDiv = document.createElement('div');
            let newImg = document.createElement('img');
            let newTit = document.createElement('h3');
            let newDes = document.createElement('p');
            body.appendChild(newDiv);
            newImg.src = itunesResponse.results[i].artworkUrl100;
            newDiv.appendChild(newImg);
            newDiv.appendChild(newTit);
            newDiv.style.color = 'rgb(100,100,100)';
            let titVal = document.createTextNode(itunesResponse.results[i].trackName);
            newTit.appendChild(titVal);
            newDiv.appendChild(newDes);
            let desVal = document.createTextNode(itunesResponse.results[i].description);
            newDes.appendChild(desVal);
        }

0 个答案:

没有答案