我有一个对话框,按下一个按钮就会打开。然后我可以填写表格并按提交,它会将行正确插入到表格中。
但是提交表单后,新插入的行提交后立即显示如下:
所以它有效,但只是在每个值之后显示 [object Object]。一旦我刷新页面,它就会消失,您可以在此处看到:
如何修复我的代码,以便它在插入一行后完全删除 [object Object]?
HTML 形式:
<form>
<fieldset>
<label for="buyer_id">Buyer ID</label>
<input type="text" name="buyer_id" id="buyer_id" value="">
<label for="name">Name</label>
<input type="text" name="name" id="name" value="">
<label for="phone">Phone Number</label>
<input type="text" name="phone" id="phone" value="">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="">
<label for="buyer">Buyer Department</label>
<input type="text" name="buyer" id="buyer" value="">
<input type="submit" id="submit">
</fieldset>
</form>
Javascript函数:
function addVendor() {
var valid = true;
allFields.removeClass( "ui-state-error" );
console.log(allFields);
if ( valid ) {
var $tr = $( "#replenishment_table tbody tr" ).eq(0).clone();
var dict = {};
var errors = "";
$.each(allFields, function(){
$tr.find('.' + $(this).attr('id')).html( $(this).val()+"-"+name );
var type = $(this).attr('id');
var value = $(this).val();
// console.log(type + " : " + value);
// ----- Switch statement that provides validation for each table cell -----
switch (type) {
case "buyer_id":
dict["Buyer-id"] = value;
break;
case "name":
dict["Name"] = value;
break;
case "phone":
dict["Phone"] = value;
break;
case "email":
dict["Email"] = value;
break;
case "buyer":
dict["Buyer_Department"] = value;
break;
}
});
回首忆惘然