国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

select在各瀏覽器中顯示option的測試結果分享

2024-07-11 08:28:55
字體:
來源:轉載
供稿:網友
這周公司要出sp3了,忙著測試產品包,我負責測試js的產品包,必須保證每一個范例都可以運行,測試了一天發現了不少問題,其中一個就是使用select的范例在ie8時顯示出問題,ie7下直接顯示不了option,經過查資料將其兼容了,這里記錄一下。
方法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>

測試結果: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>

測試結果: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>

測試結果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。
方法4:
將方法3的insertBefore第二個參數去掉,也就是說我們第一個option就想使用insertBefore時,看一下情況:

復制代碼
代碼如下:
<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>

測試結果:Chrome、Safari顯示正常,Firefox、IE9、IE8、IE7、Opera下不能顯示。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上高县| 绥阳县| 沁源县| 监利县| 大渡口区| 三河市| 东城区| 若尔盖县| 闵行区| 河西区| 巴彦淖尔市| 彰化县| 武汉市| 玉田县| 通辽市| 巴塘县| 鹤岗市| 瑞金市| 荆州市| 临邑县| 绥德县| 兖州市| 中卫市| 梧州市| 上饶县| 内乡县| 靖宇县| 郓城县| 泸水县| 蒲城县| 宁德市| 明溪县| 康定县| 扎鲁特旗| 阿坝| 天门市| 水富县| 浮山县| 英德市| 汤阴县| 改则县|