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

做了一个点击后可以增加一行的下拉单选框, 为什么在第二次点击时找不到OPTION的参数了?
<html>
<head>
<script   language= "javascript "   type= "text/javascript ">
<!--  

function   AddRowArg(tablename){
this.tablename   =   document.getElementById( "tablename ");
        var   newRow   =   tablename.insertRow(-1);

        var   Cel1Select   =   newRow.insertCell(0);
Cel1Select.innerHTML   =   ' <select   id= "argment "   > ';

var   oop   =   new   Array();
oop[1]   =   "un ";
oop[2]   =   "deux ";
oop[3]   =   "trois ";

argment.options[0]   =   new   Option( "-Faites   un   choix- ", "0 ");
for(var   i=1;   i <oop.length;   i++){
argment.options[i]   =   new   Option(oop[i],oop[i]);
}

var   CellVar   =   newRow.insertCell(1);
        CellVar.innerHTML   =   ' <input   type= "text "   id= "valbox "   > ';

var   CellCom   =   newRow.insertCell(2);
        CellCom.innerHTML   =   ' <input   type= "text "   > ';
}
-->
        </script>
</head>

<body>
        <table   border= "1 "   id= "tablearg ">
<tr> <td> 11111 </td>
<td> 22222 </td>
<td> 33333 </td> </tr>
</table> <br>

<form   name= "fbody "     method= "post ">
<input   type= "button "     value= "Addition "   OnClick= "AddRowArg(tablearg) ">
</form>

</body>
</html>

------解决方案--------------------
主要是id重名要用数组方式取的问题
<html>
<head>
<script language= "javascript " type= "text/javascript ">
<!--

function AddRowArg(tablename){
tablename = document.getElementById(tablename);
var newRow = tablename.insertRow(-1);

var Cel1Select = newRow.insertCell(0);
Cel1Select.innerHTML = ' <select id= "argment " > </select> ';

var oop = new Array();
oop[1] = "un ";
oop[2] = "deux ";
oop[3] = "trois ";

var argment = document.all.argment;
if(argment.length){argment = argment[argment.length-1];}

argment.options[0] = new Option( "-Faites un choix- ", "0 ");
for(var i=1; i <oop.length; i++){
argment.options[i] = new Option(oop[i],oop[i]);
}

var CellVar = newRow.insertCell(1);
CellVar.innerHTML = ' <input type= "text " id= "valbox " > ';

var CellCom = newRow.insertCell(2);
CellCom.innerHTML = ' <input type= "text " > ';
}
-->
</script>
</head>

<body>
<table border= "1 " id= "tablearg ">
<tr> <td> 11111 </td>
<