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

转载于:https://www.cnblogs.com/wangyulu/p/4440297.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值