我有一个表单,用户可以在其中填写静态字段。在它们下方有一个按钮允许动态添加新字段:
<form action="url" method="POST">
<table class="table" id="mytable">
<thead>
<tr>
<th>Foo</th>
<th>Bar</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button id="new-field">Add new fields</button>
</form>
这是我的 JS 代码:
$('#new-field').click(function(e) {
e.preventDefault();
var i = $('#mytable tbody tr').length + 1;
$('<tr><td><input type="text" name="newfield['+ i +'][foo]"></td><td><input type="text" name="newfield['+ i +'][bar]]"></tr>').appendTo($('#mytable tbody'));
});
新字段显示正确,但是当我发布表单(通过提交按钮)时,IE9 上不考虑新字段......它适用于 Firefox 和 Chrome。
显然这是一个解决方案:动态添加的表单元素不在 IE 9 中发布 但我不能为我的项目使用兼容模式。
请问你有什么解决办法吗?