<select id="dir" name="dir" size="1"></select><input type="button" value="go" onclick="selectadd()"><SCRIPT LANGUAGE="JavaScript">
<!--var ary = new Array();
ary["new1"] = "test1";
ary["new2"] = "test2";
ary["new3"] = "test3";
ary["new4"] = "test4";function selectadd()
{
var img = document.getElementById("dir");
for (key in ary)
{
var NewOpt = new Option(ary[key]);
img.options[img.length] = NewOpt;
}
}//-->
</SCRIPT>
<!--var ary = new Array();
ary["new1"] = "test1";
ary["new2"] = "test2";
ary["new3"] = "test3";
ary["new4"] = "test4";function selectadd()
{
var img = document.getElementById("dir");
for (key in ary)
{
var NewOpt = new Option(ary[key]);
img.options[img.length] = NewOpt;
}
}//-->
</SCRIPT>
<div id="showDIR"></div>
<script>
var oOption = document.createElement("option");
oOption.value = "1";
oOption.text = "1"
document.getElementById("dir").add(oOption);
document.getElementById("showDIR").innerHTML = "1";
</script>要的是这个吗?
dir = document.getElementById("dir");
dir.options.add(new Option("text","value"));
按索引选中:
dir.options[index].selected = true;
function createOption()
{
var dir = document.getElementById("dir");
var opval = document.getElementById("opval");
var showDIR = document.getElementById("showDIR");
if(opval.value == ""){
alert("Option must not empty.");
return;
}
var op = document.createElement("OPTION");
op.value = op.innerText = opval.value;
dir.options.appendChild(op);
showDIR.innerText = opval.value;
}
</script>
<select id="dir" name="dir"></select>
<input type="text" id="opval"> <input type="button" value="Creaet Option" onclick="createOption()">
<div id="showDIR"></div>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function cj(){ var showDir = document.getElementById('showDIR');
var dir = document.createElement('<select id="dir" name="dir" size="1"></select>');
showDir.appendChild(dir);
}
//-->
</SCRIPT>
</HEAD><BODY>
<div id="showDIR"></div>
<input type="button" onclick="cj();" value="Create div">
</BODY>
</HTML>
function create(){
var dir=document.getElementById("dir");
option=document.createElement("option");
option.value=prompt("请输入新文件夹名称:", "");
option.text=option.value;
dir.add(option);
}
</script><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="showdiv"></div>
<input type="button" name="btn1" value="创建" onclick="create();">怎么改???
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><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="showdiv"></div>
<input type="button" name="btn1" value="创建" onclick="create();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="showdiv">1</div>
<input type="button" name="btn1" value="创建" onclick="create();">
<script language="javascript">
function create(){
var dir=document.getElementById("dir");
option=document.createElement("option");
option.value=prompt("请输入新文件夹名称:", "");
option.text=option.value;
dir.add(option);
show();
}function show(){
var str = "";
var dir=document.getElementById("dir");
var showdiv=document.getElementById("showdiv");
for(i = 0; i < dir.options.length; i++)
str += dir.options[i].text + "<br/>";
showdiv.innerHTML = str;
}show();
</script>
===========================================
var o=document.getElementById("showDir");
alert(option[0].value);
=============================================
改:
var o=document.getElementById("showDiv");
alert(dir.options[0].value);