我有一个具有一对多关系的数据库结构。在html格式中,有类似的输入,其名称为“ item []”或“ file []”,以使数据成为数组
Name: Item: File: Item: File: Select: One Two
我该如何只提交更改的字段,并且在服务器端我可以确认更改了哪个项目?我尝试禁用输入,但似乎不起作用。
另一个问题是,如果我使用ajax提交表单,该如何提交文件
您可以使用jQuery解决此问题,并在每次更改后添加一个类,然后input 可以inputs不使用该类而禁用所有内容并提交表单
input
inputs
$(document).ready(function() { $('input, select, textarea').on('change', function() { $(this).addClass('changed'); }); $('form').on('submit', function() { $('input:not(.changed), textarea:not(.changed)').prop('disabled', true); // alert and return just for showing alert($(this).serialize().replace('%5B', '[').replace('%5D', ']')); return false; }); });
Name: Item: File: Item: File: Select: One Two send