日期:2014-05-16  浏览次数:20368 次

求助,js 添加 option
HTML code
<%=request("aa")%>
<script language="javascript">
<!--
function watch_ini(){ // 初始
for(var i=0; i<arguments.length; i++){
   var oOption=new Option(arguments[i],arguments[i]);
   document.getElementById("MySelect")[i]=oOption;
}
}
function watch_add(f,prj_vlaue){ // 增加
   var oOption=new Option(prj_vlaue,prj_vlaue);
   f.keywords[f.keywords.length]=oOption;
}
function watch_del(f){ // 删除
f.keywords.remove(f.keywords.selectedIndex);
}
//-->
</script>
<form name="form1" method="get" action="">
  <table width="404" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="400" height="25" ><div id="prjname" ></div></td>
    </tr>
    <tr>
      <select id="MySelect" name="keywords" size="10" ></select>
    </tr>
  </table>
<input type="submit" value="提交" name="add" />
<input type="button" value="删除" onclick="watch_del(this.form);" />
</form>

现在提交后能得到<%=request("aa")%>值,如何通过 watch_add(f,prj_vlaue)函数添加option呢?
折腾很久没整出来。。。。(我要的效果是可以添加多少option)

------解决方案--------------------
JScript code
function watch_add(f, prj_value) {
    f.keywords.add(new Option(prj_value, prj_value), null);
}

------解决方案--------------------

<form name="form1" method="get" action="">
<table width="404" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="400" height="25" ><div id="prjname" ></div></td>
</tr>
<tr>
<select id="MySelect" name="keywords" size="10" ></select>
</tr>
</table>
<input type="submit" value="提交" name="add" />
<input type="button" value="删除" onclick="watch_del(this.form);" />
</form>
<script language="javascript">
<!--
function watch_ini(){ // 初始
for(var i=0; i<arguments.length; i++){
var oOption=new Option(arguments[i],arguments[i]);
document.getElementById("MySelect")[i]=oOption;
}
}
function watch_add(f,prj_value){ // 增加
f.add(new Option(prj_value, prj_value));
}
var test = '<%=request("aa")%>';
var obj = document.getElementById('MySelect');
watch_add(obj, test)
function watch_del(f){ // 删除
f.keywords.remove(f.keywords.selectedIndex);
}
//-->
</script>



这个意思?