我正在使用如下所示的嵌入式js腳本製作select元素。我確實看到在頁面上有一個select元素,但下拉列表是空白的。默認選擇也不顯示。我認爲CSS不能正常工作的原因是尺寸太小。我做了一個靜態選擇不是從JS,它是更大。有什麼建議麼?由JavaScript創建的元素未被CSS文件格式化
* UDPATE *
我追加選擇元素,但現在我有兩個。一個有選擇並且不受CSS影響的,一個是由CSS表單正確格式化的空白。是什麼賦予了?
<script>
function processCSV(file,parentNode)
{
var frag = document.createDocumentFragment()
, lines = file.split('\n'), option;
var intial_option = document.createElement("option");
intial_option.setAttribute("value","");
intial_option.setAttribute("disabled","disabled");
intial_option.setAttribute("selected","selected");
intial_option.innerHTML = "Please select a Plant";
frag.appendChild(intial_option)
for (var i = 0, len = lines.length; i < len; i++){
option = document.createElement("option");
option.setAttribute("value", lines[i]);
option.innerHTML = lines[i];
frag.appendChild(option);
}
parentNode.appendChild(frag);
menuholder.appendChild(parentNode);
}
var plant_select = document.createElement("select");
var datafile = '';
var xmlhttp = new XMLHttpRequest();
plant_select.setAttribute("class", "selectbox");
plant_select.setAttribute("id", "plant_select");
xmlhttp.open("GET","http://localhost:8080/res/plants.csv",true);
xmlhttp.send();
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.status==200 && xmlhttp.readyState==4)
{
processCSV(xmlhttp.responseText, plant_select);
}
}
</script>
的coresponding CSS文件部分如下所示
body
{
padding: 0;
margin: 0;
background-color:#d0e4fe;
font-size: 2em;
font-family: monospace;
font-weight: bold;
}
和
.menu_container
{
position: relative;
margin: 0 auto;
}
.menu_element
{
float: right;
width: 33%;
}
你可以發佈生成的HTML嗎? –
也許是一個愚蠢的問題 - 但你是否試圖通過螢火蟲/鉻檢查生成的代碼位,以檢查是否正在應用所需的類等? –
哪些瀏覽器遇到過這個問題? – JAL