[英]Form serialize does not include table
我具有此功能來檢查表單中是否有更改,顯然它可以正常工作:
$(function() {
var init_form = $('#editarproduto').serialize();
$(':submit').click(function() {
window.onbeforeunload = null;
});
window.onbeforeunload = function() {
var check_form = $('#editarproduto').serialize();
console.log(check_form);
console.log(init_form);
if (check_form === init_form)
return null;
return 'Os dados do formulário não foram salvos, deseja permanecer nesta página?';
};
});
但是這帶來了他需要檢查表的需要,如果其中隱藏了某些內容,則不會對表進行更改:
<table class="table table-responsive table-hover" id="tabelaf" name="tabelaf">
<tbody>
@foreach (var item in Model.ProdutosFornecedores) {
<tr class="tr item">
<td>@item.FornecedorProduto.Id</td>
<td>@item.FornecedorProduto.Nome</td>
<td align="right">
<a class="link-excluir" href="#" data-id="@item.Id" title="Excluir"><i class="fa fa-trash-o fa-lg"></i></a>
</td>
</tr>
}
</tbody>
</table>
您也如何將其與此表進行比較?
您的序列化僅從表單元素獲取數據。 您可以將隱藏的輸入添加到列中,以將該數據包括在表單中:
<td>
@item.FornecedorProduto.Id
<input type="hidden" name="id" value="@item.FornecedorProduto.Id" />
</td>
請注意,此表應放置在表單內
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.