dongtu9823 2012-10-19 21:03 采纳率: 0%
浏览 273

使用javascript将文本框数组添加到html中出错

我的代码哪里错了?

    <script>
        function add(){
            /* Get your form */
        form = document.getElementById("test");
            /* Create your input element */
        input = document.createElement("input");
        input.type="text";
        input.name="array['artists']";
            /* Append to form */
        form.appendChild(input);
        alert("done");
        }
    </script>

<table>
<tr>
 <td align="right">Artist/s:</td>
 <td><form id="test" enctype="multipart/data-form" method="post">
 <input type="text" name="artists"/>
 <input type="button" onclick='javascript: add()'/></form></td>
</tr>
<tr>
 <td colspan="2"><input type="submit" value="Submit"></td>
</tr>
</table>

我试图在另一个文本框下面添加另一个文本框,但是什么也没有发生。我该怎么做?

  • 写回答

4条回答 默认 最新

  • dongluo6343 2012-10-19 21:10
    关注

    Seems to be working - fiddle

    I just put a call to add() inside a setTimeout so it would execute a second after the page loads.

    Are you just missing the call to add()?

    edit: I didnt originally see the onclick bound. new working fiddle2

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条