日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

select 在各浏览器中显示option的测试结果分享

發(fā)布時間:2025/4/5 HTML 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 select 在各浏览器中显示option的测试结果分享 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

原網(wǎng)址:http://www.jb51.net/css/76690.html

使用select的范例在ie8時顯示出問題,ie7下直接顯示不了option,經(jīng)過查資料將其兼容了,這里記錄一下,感興趣的朋友可以參考下哈,希望可以幫助到你

方法1: 代碼如下: <html> <head> <title></title> <script type="text/javascript"> function init() { var s = document.getElementById("s"); s.add(new Option("A")); } </script> </head> <body οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html>

測試結(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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html>

測試結(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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html> 測試結(jié)果:Firefox、Chrome、Safari、Opera顯示正常,IE9、IE8、IE7下不能顯示。 方法4: 將方法3的insertBefore第二個參數(shù)去掉,也就是說我們第一個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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html> 測試結(jié)果: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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html> 測試結(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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html> 測試結(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 οnlοad="init()"> <select id="s" style="width:100px;background:lightskyblue"></select> </body> </html>

總結(jié)

以上是生活随笔為你收集整理的select 在各浏览器中显示option的测试结果分享的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。