select在各浏览器中显示option的测试结果分享
建站知识 2021-07-03 08:43www.168986.cn长沙网站建设
这周公司要出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下不能显示。
方法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>
测试结果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>
测试结果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>
测试结果Firefox、Chrome、Safari、Opera显示正常,IE9、IE8、IE7下不能显示。
方法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下不能显示。
方法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>
测试结果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>
测试结果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>
测试结果Firefox、Chrome、Safari、Opera显示正常,IE9、IE8、IE7下不能显示。
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键