高手指教一二 删除某选项: options.remove(iIndex); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 添加选项:var oOption = document.createElement("OPTION");oSelect.options.add(oOption);oOption.innerText = "Two";oOption.value = "2";都是从帮助文档里拷贝来得, 以下仅仅是一段示意性代码,<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script language="javascript"> function hehe() { //取得当前选项 text1=document.all.select1.options[document.all.select1.options.selectedIndex].text; index1=document.all.select1.options.selectedIndex; //删除 document.all.select1.options.remove(index1); //新增道另一边 oOption = document.createElement("OPTION"); document.all.select2.options.add(oOption); oOption.innerText = text1; }</script></head><body><form name="form1" method="post" action=""> <p> <select name="select1" size="4" > <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <input type="button" name="Submit" value="删除" onClick="hehe();"> <select name="select2" size="4"> <option>a</option> <option>b</option> <option>c</option> </select></p> <p> </p> <p> </p> <p> </p></form></body></html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><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 left(){ if(document.all.select2.selectedIndex>=0) { var o = new Option(); o.text = document.all.select2.options[document.all.select2.selectedIndex].text; document.all.select1.options.add(o); document.all.select2.remove(document.all.select2.selectedIndex); } }function right(){ if(document.all.select1.selectedIndex>=0) { var o = new Option(); o.text = document.all.select1.options[document.all.select1.selectedIndex].text; document.all.select2.options.add(o); document.all.select1.remove(document.all.select1.selectedIndex); }}//--></SCRIPT></HEAD><BODY><form name="form1" method="post" action=""> <p> <select name="select1" size="4" > <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <input type="button" name="Submit" value="<<" onClick="left();"> <input type="button" name="Submit" value=">>" onClick="right();"> <select name="select2" size="4"> <option>a</option> <option>b</option> <option>c</option> </select></p></form></BODY></HTML> jquery的问题 JS怎么传递一个函数? 谁看得懂这段javascript代码 google api 点击按钮,执行另一个页面的程序,但无需跳转??? FCKeditor字数的问题 js截图 innerHTML中的控件不能附值 使用XMLHTTP出错,如何解决? 自定义对话框的问题 如何用Javascript实现下面功能? 现在的在线html编辑器都只支持IE,有可以在非IE下使用的吗?
var oOption = document.createElement("OPTION");
oSelect.options.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
都是从帮助文档里拷贝来得,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
function hehe()
{
//取得当前选项
text1=document.all.select1.options[document.all.select1.options.selectedIndex].text;
index1=document.all.select1.options.selectedIndex;
//删除
document.all.select1.options.remove(index1);
//新增道另一边
oOption = document.createElement("OPTION");
document.all.select2.options.add(oOption);
oOption.innerText = text1;
}
</script>
</head><body>
<form name="form1" method="post" action="">
<p>
<select name="select1" size="4" >
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<input type="button" name="Submit" value="删除" onClick="hehe();"> <select name="select2" size="4">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</p>
<p> </p>
<p> </p>
<p> </p>
</form>
</body>
</html>
<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 left()
{
if(document.all.select2.selectedIndex>=0)
{
var o = new Option();
o.text = document.all.select2.options[document.all.select2.selectedIndex].text;
document.all.select1.options.add(o);
document.all.select2.remove(document.all.select2.selectedIndex);
}
}function right()
{
if(document.all.select1.selectedIndex>=0)
{
var o = new Option();
o.text = document.all.select1.options[document.all.select1.selectedIndex].text;
document.all.select2.options.add(o);
document.all.select1.remove(document.all.select1.selectedIndex);
}}//-->
</SCRIPT>
</HEAD><BODY>
<form name="form1" method="post" action="">
<p>
<select name="select1" size="4" >
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<input type="button" name="Submit" value="<<" onClick="left();">
<input type="button" name="Submit" value=">>" onClick="right();"> <select name="select2" size="4">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</p>
</form>
</BODY>
</HTML>