0

我有一个表格和 2 个按钮来添加和删除一组通过 Jquery 动态添加的 html 元素。当我提交表格时。操作页面仅打印手动编码的表单元素。

我已经用 $('#myTable tr:last').after(newElem);

在 jQuery 中。

这是链接 www.jsfiddle.net/abelkbil/3GbWH/3/

这样的输出

Array ( [rno] => 123 [adno] => Array ( [0] => 1235 它没有打印 [1]=>x ) [rel....

感谢所有的支持

4

2 回答 2

1

form标签未在 html 中关闭。它还应该包含两个嵌套表。

    <form name="f10"  id="myform" method=POST action="http://testxml.net84.net/abel-test/test.php">
    <table id="myTable">
    <tbody>
    <tr><th><th><th><th><th>Ration Number</th><td><input type="text" name="rno"></td><th>Grand total</th><td><input type="text" name="adno[0]"></td></tr>
    <tr><th>Aadaar Number</th><th>Relationship</th><th>Income from land</th><th>Salary/Pension</th><th>Income from business</th><th>Income from Labour</th><th>Rental Income</th><th>Any other income</th><th>total
    </th></tr>
    <input type="hidden" id="rowcount" value="1" >
    <tr><td><input type="text" name="adno[0]"></td>
    <td>
    <select name="relation">
    <option  value="owner">owner</option>
    <option  value="Father">Father </option>
    <option  value="Mother">Mother</option>
    <option  value="Son">Son</option>
    <option  value="Daughter">Daughter</option>
    <option  value="Husband">Husband</option>
    <option  value="Grandfather">Grandfather</option>
    <option value=" Grandmother">Grandmother</option>
    <option value="Mother-in-law">Mother-in-law</option>
    <option value="Father-in-law 8">Father-in-law</option>
    </select></td>
    <td><input type="text" name="il"></td>
    <td><input type="text" name="sal"></td>
    <td><input type="text" name="lb" ></td>
    <td><input type="text" name="ll" ></td>
    <td><input type="text" name="rl" ></td>
    <td><input type="text" name="ai" ></td>
    <td><input type="text" name="tot" ></td>
    </tr>
    </tbody>
    </table>
    <table>
    <tr><td><input type="submit" name="submit"></td></tr>
    <tr><td>


            <input type="button" id="btnAdd" value="add another name" /></td><td>
            <input type="button" id="btnDel" value="remove name" /></td>
       </tr>
    </table>
</form>
于 2012-12-01T08:26:22.760 回答
1

您尚未添加结束表单标记。我会添加它并将开始表单标签移动到表格之外,但这只是我的偏好。

<form name="f10"  id="myform" method=POST action="http://testxml.net84.net/abel-test/test.php">
    <table id="myTable">
        .. table ..
    </table>
</form>

此外,您只是为添加的adno['+rows+']脚本的一部分添加一个数组。因此,即使添加了表单标签,您也只会在打印的数组中获得额外的 adno 标签。

为此,您应该将元素命名为数组的一部分,因此name=relation将成为name=adno['+rows+'][relation]. 然后每一行新元素将成为输出数组中的新行。

于 2012-12-01T08:39:45.890 回答