"重命名"? do you mean change the selected text? if so, try something like
<form name="form1">
<select name="sel1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="button" value="change text" onclick="changeText()">
</form><script language="javascript">
function changeText()
{
var select = document.form1.sel1;
if (select.selectedIndex < 0)
alert("Please select an item");
else
{
var s = prompt("enter a new text");
if (s != null)
{
select.options[select.selectedIndex].text = s;
}
}
}
</script>
<form name="form1">
<select name="sel1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="button" value="change text" onclick="changeText()">
</form><script language="javascript">
function changeText()
{
var select = document.form1.sel1;
if (select.selectedIndex < 0)
alert("Please select an item");
else
{
var s = prompt("enter a new text");
if (s != null)
{
select.options[select.selectedIndex].text = s;
}
}
}
</script>
是这个程序要点,她的功能是得到被选项的文本内容
<option>asdfasd</option>
<option>asdfasd</option>
<option>asdfasd</option>
<option>asdfasd</option>
<option>asdfasd</option>
</select><input id=te><input type=button onclick="rename()"><script>
function rename()
{
se.options[se.selectedIndex].text = te.value;
}
</script>
{
se.options[se.selectedIndex].text = te.value;
se.options[se.selectedIndex].value = te.value;
}
你的是dropdown的
只是把dropdown改为listbox就是了
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="button" value="change text" onclick="sel1.options[sel1.selectedIndex].text=prompt('enter a new text')">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="button" value="change text" onclick="sel1.options[sel1.selectedIndex].text=prompt('enter a new text')">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="button" value="change text" onclick="s=sel1.selectedIndex;if(s!='-1'){sel1.options[s].text=prompt('enter a new text')}">
{
var change = document.form1.Select1;
if (change.selectedIndex < 0)
alert("请选择一个要更改的选项名!");
else
{
var s = prompt("输入一个新的名字!");
if (s != null)
{
change.options[change.selectedIndex].text = s;
}
}
}