<select id="dir" name="dir" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="showDir"></div>
<input type="button" name="btn1" value="创建" onclick="create();">
<script language="javascript">
showDir();
function create(){
var dir=document.getElementById("dir");
option=document.createElement("option");
var o=document.getElementById("showDir");
//alert(option[0].value);
option.value=prompt("请输入新文件夹名称:", "");
option.text=option.value;
dir.add(option);
o.innerHTML+=option.value;
}
function showDir(){
var o=document.getElementById("dir");
var div=document.getElementById("showDir");
var s="";
for(var i=0;i<o.options.length;i++){
s+=o.options[i].text+":"
}
div.innerHTML=s;
}
</script>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="showDir"></div>
<input type="button" name="btn1" value="创建" onclick="create();">
<script language="javascript">
showDir();
function create(){
var dir=document.getElementById("dir");
option=document.createElement("option");
var o=document.getElementById("showDir");
//alert(option[0].value);
option.value=prompt("请输入新文件夹名称:", "");
option.text=option.value;
dir.add(option);
o.innerHTML+=option.value;
}
function showDir(){
var o=document.getElementById("dir");
var div=document.getElementById("showDir");
var s="";
for(var i=0;i<o.options.length;i++){
s+=o.options[i].text+":"
}
div.innerHTML=s;
}
</script>
var o=document.getElementById("showDir");
alert(option[0].value);
=============================================
改:
var o=document.getElementById("showDiv");
alert(dir.options[0].value);