IE8 innerHTML赋值时包含多级HTML标签时的解决方案

var inhtml = '';

var font = document.createElement("font");
var a = document.createElement("a");
var div = document.createElement("div");
font.style.fontSize = "18px";

if (str == 0) {

font.style.color = "#33CC33";
font.innerHTML = "恭喜你,都答对了,请进入下一题库";
a.href = "/index.php/onlinecource/retroaction/id/" + cat_id;
a.className = "answer_a";
div.appendChild(a);

} else {

font.style.color = "#97171B";
font.innerHTML = "抱歉,第" + str + "题答错了,请查看正确答案后作出修改";
a.href = "/index.php/onlinecource/correctanswer/id/" + cat_id;
a.className = "noneanswer_a";
a.innerHTML = "正确答案";
div.appendChild(a);

}

txt.appendChild(font);

txt.appendChild(div);

document.getElementById('msgDiv').appendChild(txt);

以上JS代码是本人在之前项目里所经历过的,在这里与大家分享下,望能够帮助大家在遇到这类问题时可以快速得到解决!

posted @ 2015-04-19 22:48  wangyulu  阅读(419)  评论(0编辑  收藏  举报