就是:比如说:这段代码:<html>
<head>
</head>
<body>
<table id="flowtable" width=100%>
<tr>
<td>
<input type=button value="click me" onclick="change()">
</td>
</tr>
</table>
</body>
</html>
<script>
var j=0
function change(){
    j=2;
    newRow=document.all.flowtable.insertRow(-1);
    newcell=newRow.insertCell();    newcell.innerHTML=j;
    newcell=newRow.insertCell();newcell.innerHTML="<select name=\"select\"><option value=1>1</option><option value=2>2</option></select>";
   newcell=newRow.insertCell();
   alert(flowtable.innerHTML);
}
</script>其中select中的option的数量是动态的,当select的length为0时,提示出错并返回,怎么写呢?

解决方案 »

  1.   

    <html>
    <head>
    </head>
    <body>
    <div id="bao"></div>
    <tr>
    <td>
    <input type=button value="click me" onclick="check()">
    </td>
    </tr>
    </table>
    </body>
    </html>
    <script>
    bao.innerHTML="<select id=\"sel1\"><option value=1>1</option><option value=2>2</option></select>";
    function check()
    {
        sel = document.getElementById("sel1");
        alert(sel.options.length);
    }
    </script>
      

  2.   

    和 你 平 常 判 断 不 是 在 innerHTML 中 的 方 法 一 样 。
      

  3.   

    在innerHTML里加另外的一个<form name="f2">标签就可以很容易的做到了