我有以下css代码
#gel{position:absolute; width:20px; height:22px; margin-left:5px; color:#FF0000;background:url('../images/GEL-CURENCY.jpg') repeat-x;background-color:transparent;}
这是我的脚本
document.getElementById("small_txt_container_2").innerHTML = '<span id=\"gel\"></span>';
在IE 8中不起作用,请帮我解决这个问题
发布于 2016-05-03 13:39:20
如果问题只出现在IE8中,则在<head>
中包含此逻辑
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
发布于 2016-05-03 13:39:27
innerHTML
指的是HTML标记内部的内容,而不是标记本身。看看这个示例,它将帮助您理解如何使用纯JS将新的<span>
添加到您的页面中。
(function(){
// 1- Establish new element
var newItem = document.createElement('span');
// 2- Add className
newItem.className = 'gel';
// 3- Put content into <span> tags
newItem.innerHTML = 'stuff inside the brackets';
// 4- Tell your program to put the span just after an item with your-ID-here
document.getElementById('your-ID-here').appendChild(newItem);
})();
https://stackoverflow.com/questions/37005668
复制