编辑:我简化了使用文本输入的示例。同样的错误。从表单中删除输入时,表单无法提交。编辑:在 Firefox 14 中重复。Chrome 没有相同的行为。
我有一个带有 jquery 的多文件上传表单,可以在表单中添加和删除文件输入元素。如果我删除其中一个输入,则 form.submit() 函数不会继续。下面是使用“文本”输入的简化代码。还有一个小提琴http://jsfiddle.net/carbontax/rMmuE/
<form id="form-foo" method="POST">
<div id="input-container-container">
</div>
</form>
<input type="button" id="add-text-input" value="ADD TEXT INPUT">
<input type="button" id="submit" value="SUBMIT">
脚本
$('#submit').click(function() {
$('#form-foo').submit();
});
$("#add-text-input").click(function() {
var div = $('<div/>', {
'class': 'input-container'
}).append($('<button/>', {
'class': 'delete-text-input',
html: "X"
}));
var input = $('<input/>', {
type: 'text',
name: 'texts',
'class': 'input-text'
}).appendTo(div);
div.appendTo($('#input-container-container'));
});
$('#form-foo').on('click', 'button.delete-text-input', function(e) {
e.preventDefault();
$(this).closest('div').remove();
});