2016-05-03 226 views
0

我有下面的CSS代碼CSS背景圖像不顯示IE8

#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的工作,請大家幫我解決這個問題

回答

0

如果問題只出現在IE8中,則將此邏輯包含在<head>

<!--[if lt IE 9]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
+0

我試試這個,但它不工作:( – zuri

0

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);   
})(); 
+0

我需要在HTML文本後顯示的圖像,所以我使用了HTML span元素的CSS類。CLAS的css行之有效的文字顏色等,但背景財產doew不工作 – zuri

+0

我的主要問題是,我想在文本後使用gergian貨幣標誌/圖標。IE 8不顯示我的圖標它看起來像'₾'。我無法找到aprobriate unicode字符,所以我希望使用跨度元素與圖像backgrount。但它不工作太 – zuri

+0

'textContent'允許您將unicode字符放入JS生成的DIV:https://developer.mozilla.org/en-US/docs/Web/API/Node/ textContent,但它只是IE9以上,你可能需要一個polyfill - 檢查鏈接它顯示你如何。 – staypuftman