我有Javascript的問題。我試圖在多選框中爲一個選項設置背景圖片。這適用於Firefox 3.6.14,但不適用於Internet Explorer 8.我已經做了一個簡短的代碼示例來向您顯示問題。有沒有人有我的問題的解決方案?style.backgroundImage僅適用於Firefox
<html>
<head>
<script language="javascript" type="text/javascript">
function changeIssueTypes(){
var testSelect = document.getElementById("testSelect");
var comboBoxTest = document.getElementById("comboBoxTest");
testSelect.options.length = 0;
if(comboBoxTest.value == 'optionTest1')
{
testSelect.options[0] = new Option();
testSelect.options[0].value = 'testOption1';
testSelect.options[0].innerHTML = 'Test option 1';
testSelect.options[0].style.backgroundImage = 'url(http://www.multimove.nl/images/icons/small/icon_document.gif)';
testSelect.options[0].style.backgroundRepeat = 'no-repeat';
}
if(comboBoxTest.value == 'optionTest2')
{
testSelect.options[0] = new Option();
testSelect.options[0].value = 'testOption1';
testSelect.options[0].innerHTML = 'Test option 1';
testSelect.options[0].style.backgroundImage = 'url(http://www.middelburg.nl/static/middelburgpresentation/images/icons/icon_pdf.gif)';
testSelect.options[0].style.backgroundRepeat = 'no-repeat';
}
}
</script>
</head>
<body>
<form>
<select id="comboBoxTest" onchange="changeIssueTypes()">
<option value="optionTest1" >Option test 1</option>
<option value="optionTest2" >Option test 2</option>
</select>
<br/>
<select multiple id="testSelect">
<option value="initialOption">Test initial option</option>
</select>
</form>
</body>
</html>
選擇框是出了名的難風格。這可能無法使用正常的控件 – 2011-03-05 21:45:59