select在各瀏覽器中顯示option的測(cè)試結(jié)果分享
發(fā)布時(shí)間:2013-03-28 15:05:27 作者:佚名
我要評(píng)論

使用select的范例在ie8時(shí)顯示出問(wèn)題,ie7下直接顯示不了option,經(jīng)過(guò)查資料將其兼容了,這里記錄一下,感興趣的朋友可以參考下哈,希望可以幫助到你
這周公司要出sp3了,忙著測(cè)試產(chǎn)品包,我負(fù)責(zé)測(cè)試js的產(chǎn)品包,必須保證每一個(gè)范例都可以運(yùn)行,測(cè)試了一天發(fā)現(xiàn)了不少問(wèn)題,其中一個(gè)就是使用select的范例在ie8時(shí)顯示出問(wèn)題,ie7下直接顯示不了option,經(jīng)過(guò)查資料將其兼容了,這里記錄一下。
方法1:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.add(new Option("A"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法2:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.appendChild(new Option("B"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法3:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.add(new Option("A"));
s.insertBefore(new Option("B"), s.options[1]);
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法4:
將方法3的insertBefore第二個(gè)參數(shù)去掉,也就是說(shuō)我們第一個(gè)option就想使用insertBefore時(shí),看一下情況:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.insertBefore(new Option("D"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Chrome、Safari顯示正常,F(xiàn)irefox、IE9、IE8、IE7、Opera下不能顯示。
方法5:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.options[0] = new Option("E");
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法6:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
var op = document.createElement("option");
op.appendChild(document.createTextNode("F"));
s.appendChild(op);
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法7:
代碼如下:
<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.innerHTML = "<option>X</option><option>Y</option>";
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法1:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.add(new Option("A"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法2:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.appendChild(new Option("B"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法3:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.add(new Option("A"));
s.insertBefore(new Option("B"), s.options[1]);
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法4:
將方法3的insertBefore第二個(gè)參數(shù)去掉,也就是說(shuō)我們第一個(gè)option就想使用insertBefore時(shí),看一下情況:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.insertBefore(new Option("D"));
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Chrome、Safari顯示正常,F(xiàn)irefox、IE9、IE8、IE7、Opera下不能顯示。
方法5:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.options[0] = new Option("E");
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法6:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
var op = document.createElement("option");
op.appendChild(document.createTextNode("F"));
s.appendChild(op);
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、IE9、IE8、IE7、Safari、Opera顯示正常。
方法7:
代碼如下:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
<script type="text/javascript">
function init()
{
var s = document.getElementById("s");
s.innerHTML = "<option>X</option><option>Y</option>";
}
</script>
</head>
<body onload="init()">
<select id="s" style="width:100px;background:lightskyblue"></select>
</body>
</html>
測(cè)試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
相關(guān)文章
- 這篇文章主要介紹了淺談原生頁(yè)面兼容IE9問(wèn)題的解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起2020-12-16
新版chrome瀏覽器設(shè)置允許跨域的實(shí)現(xiàn)
這篇文章主要介紹了新版chrome瀏覽器設(shè)置允許跨域的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起2020-11-30css hack之\9和\0就可能對(duì)hack IE11\IE9\IE8無(wú)效
每次設(shè)計(jì)一張網(wǎng)頁(yè)或一個(gè)表單,都被各種瀏覽器的兼容問(wèn)題傷透腦筋,尤其是IE家族。在做兼容性設(shè)計(jì)時(shí),我們往往會(huì)使用各種瀏覽器能識(shí)別的獨(dú)特語(yǔ)法進(jìn)行hack,從而達(dá)到各種瀏覽2020-03-20css區(qū)分ie8/ie9/ie10/ie11 chrome firefox的代碼
這篇文章主要介紹了css區(qū)分ie8/ie9/ie10/ie11 chrome firefox的代碼,需要的朋友可以參考下2020-03-20- 這篇文章主要介紹了解決CSS瀏覽器兼容性問(wèn)題的4種方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)2020-02-28
- 這篇文章主要介紹了常見的瀏覽器兼容性問(wèn)題(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)2020-02-20
- 這篇文章主要介紹了border-radius IE8兼容處理的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)2020-02-12
淺談?dòng)龅降膸讉€(gè)瀏覽器兼容性問(wèn)題
這篇文章主要介紹了淺談?dòng)龅降膸讉€(gè)瀏覽器兼容性問(wèn)題,詳細(xì)的介紹了幾種我遇到的問(wèn)題和解決方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-09-26- 這篇文章主要介紹了base64圖片在各種瀏覽器的兼容性處理的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-14
對(duì)常見的css屬性進(jìn)行瀏覽器兼容性總結(jié)(推薦)
這篇文章主要介紹了對(duì)常見的css屬性進(jìn)行瀏覽器兼容性總結(jié)(推薦)的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-20