2013-05-13 29 views
1

以下代碼在除Internet Explorer 9之外的其他任何瀏覽器中都能很好地工作。 顏色透明CSS不起作用。透明色在Internet Explorer中不起作用

HTML:

<select class="selectElement" runat="server" id="dropdown_"> 
    <option value="N">N</option> 
    <option value="G">G</option> 
    <option value="O">O</option> 
    <option value="A">A</option> 
    <option value="R">R</option> 
    <option value="U">U</option> 
</select> 

CSS:

.selectElement { 
    height: 50px; 
    width: 80px; 
    border: solid 1px #c8c8c8; 
    color:transparent; 
} 

的jQuery:

$(document).ready(function() { 
    $('select[id^=dropdown]').children().each(function() { 
     colors = { "N": "lightgrey", "G": "green", "O": "orange", "A": "yellow", "R": "red", "U": "purple" } 
     $(this).attr('style', 'background-color:' + colors[$(this).val()] + ';'); 
    }); 
    $('select[id^=dropdown]').change(function() { 
     $(this).attr('style', $(this).find('option:selected').attr('style')); 
    }).change(); 
    $('select[id^=dropdown]') 
    .mousedown(function() { $(this).css('color', 'black') }) 
    .blur(function() { SetStyle(this) }) 
    .change(function() { SetStyle(this) }) 

    SetStyle('#dropdown'); // So that we style on load 

    function SetStyle(obj) { 
     var color = $(obj).find('option:selected').css('background-color'); 
     $(obj).css({ 
      'color': 'rgba(0,0,0,0)', 
      'background-color': color 
     }); 
    } 
}); 
+0

您在IE中呈現哪種文檔模式?什麼是您使用的文檔類型? – teewuane 2013-05-13 15:22:43

+0

我正在使用ASP.NET web表單 – Singh 2013-05-13 15:25:51

+0

Jag,看看你的html。在.aspx開頭或其他地方,你會看到<!doctype html>或類似的東西。此外,你可以推F12(從Windows)來拉動IE中的開發工具。您將在那裏看到文檔模式和瀏覽器模式。它是什麼? – teewuane 2013-05-13 15:27:05

回答

1

我認爲你將有一個很難試圖讓選擇菜單樣式,你想要做什麼,除非你使用像jQuery自定義選擇的插件。

http://adam.co/lab/jquery/customselect/

話雖這麼說,不是這樣...

$(this).attr('style', 'background-color:' + colors[$(this).val()] + ';'); 

你可以試試這個...

$(this).css({'background-color': colors[$(this).val()]}); 

而且,如果IE瀏覽器給你任何錯誤有用的消息。

+0

感謝您的鏈接 - 它真的幫助! :) – Singh 2013-05-13 22:16:42

1

它是無效的直接改變style屬性在IE中。

相反,試試這個:

this.cssText = this.options[this.selectedIndex].cssText; 
+0

我可以使文本顏色匹配的背景顏色,這給了我想要什麼,但是當下拉打開時,用戶需要能夠看到什麼顏色意味着 – Singh 2013-05-13 15:32:15

相關問題