jquery - 可编辑的表,但保存所有值
问题描述
只是遇到了障碍,我也有一个很大的表格,大多数单元格都是可编辑的,但我想单击提交按钮并保存所有单元格中的所有值。
这是我目前拥有的:
$(".edit").focusout(function(){
//$("#sub").click(function() {
$(this).removeClass("editMode");
var id = this.id;
var split_id = id.split("_");
var field_name = split_id[0];
var edit_id = split_id[1];
var value = $(this).text();
$.ajax({
url: '/claim/store',
type: 'post',
data: { field:field_name, value:value, id:edit_id },
success:function(response){
console.log('Save successfully');
}
});
});
哪个有效,但一次只能执行一个单元格,并且对于 ajax 帖子,我需要发送所有内容,以便我可以对其进行编码并保存到数据库。
我有这是一个 Laravel 刀片 foreach:
@foreach($costItems as $key => $cost)
<tr>
<td>{{ $key }}</td>
<td colspan="6">{{ $cost}}</td>
<td contentEditable="true" class="edit" id="total_budget_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q1_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q2_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q3_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q4_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q5_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q6_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q7_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q8_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q9_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q10_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q11_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="q12_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="project_total_{{ $key }}"></td>
<td contentEditable="true" class="edit" id="variance_{{ $key }}"></td>
</tr>
任何帮助都非常感谢,以便一次性保存所有已编辑的值。
解决方案
推荐阅读
- python - 如何在没有 UI 交互的情况下使用 python 连接 Microsoft Graph?
- scala - 如何从 Spark.scala 访问 HBase?有明确定义的scala api吗?
- javascript - 键入一个函数,该函数接受与对象类型匹配的键和值,然后使用它们
- css - 如何将样式类添加到 Angular 5 中创建的 ComponentRef?
- jpa - java.lang.ClassNotFoundException:来自 JPA 控制台的 javax.persistence.spi.PersistenceUnitInfo
- ios - 如何正确编写 Rails API 控制器以执行与 iOS 客户端的完全同步
- java - “令牌语法错误”;“, , 预期”
- javascript - export 作为在 javascript 上导出模块的语句的好处和用法?
- python - 用于张量流中不同数量元素的标签和预测的精度和召回 eval_metrics
- javascript - 分页 AngularJS 发布应用程序性能问题