非常感谢您的帮助。我找到了解决我的问题的方法。我使用contenteditable="true" 将整个表格更改为可编辑表格,并且它可以工作。使用contenteditable,您可以将数据从网页发布到数据库,而无需重新加载页面。而且我正在模态框内展示我的整个表格,效果很好。
index.php
<table class="table table-bordered" id="myTable">
<thead>
<tr>
<th class="fixed-column"><strong> Issues </strong></th>
<th class="text-align"><strong> Test Object </strong></th>
<th class="text-align"><strong> HW and SW Delivery Issues </strong></th>
<th class="text-align"><strong> Status at Previous MRD </strong></th>
<th class="text-align"><strong> Recommendation Previous CRB </strong></th>
<th class="text-align"><strong> Functional Implementation on Status </strong></th>
<th class="text-align"><strong> Issues for Upcoming Activities </strong></th>
<th class="text-align"><strong> System Verification Status </strong></th>
<th class="text-align"><strong> Next Check Point </strong></th>
<th class="text-align"><strong> Last Updated </strong></th>
<th class="text-align"><strong> Comments </strong></th>
<th class="text-align"><strong> Action Point </strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['Issues']; ?>" onBlur="saveInLineEdit(this, 'Issues', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['Issues']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['testObject']; ?>" onBlur="saveInLineEdit(this, 'testObject', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['testObject']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['deliveryIssues']; ?>" onBlur="saveInLineEdit(this, 'deliveryIssues', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['deliveryIssues']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['prevMRD']; ?>" onBlur="saveInLineEdit(this, 'prevMRD', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['prevMRD']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['prevCRB']; ?>" onBlur="saveInLineEdit(this, 'prevCRB', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['prevCRB']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['Func_Imple']; ?>" onBlur="saveInLineEdit(this, 'Func_Imple', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['Func_Imple']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['upcomingIssues']; ?>" onBlur="saveInLineEdit(this, 'upcomingIssues', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['upcomingIssues']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['statusVerify']; ?>" onBlur="saveInLineEdit(this, 'statusVerify', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['statusVerify']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['nextChkPoint']; ?>" onBlur="saveInLineEdit(this, 'nextChkPoint', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['nextChkPoint']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['lastUpdated']; ?>" onBlur="saveInLineEdit(this, 'lastUpdated', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['lastUpdated']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['Comments']; ?>" onBlur="saveInLineEdit(this, 'Comments', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['Comments']; ?></td>
<td class="text-align" contenteditable="true" data-old_value="<?php echo $item['actionPoint']; ?>" onBlur="saveInLineEdit(this, 'actionPoint', '<?php echo $row_id; ?>')" onClick="highlightEdit(this);"><?php echo $item['actionPoint']; ?></td>
</tr>
</tbody>
</table>
函数.js
function highlightEdit(editableObj) {
$(editableObj).css("background","#FFF");
}
function saveInLineEdit(editableObj,column,id) {
// no change change made then return false
if($(editableObj).attr('data-old_value') === editableObj.innerHTML)
return false;
// send ajax to update value
$(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
$.ajax({
url: "saveInlineEdit.php",
cache: false,
data:'column='+column+'&value='+editableObj.innerHTML+'&id='+id,
success: function(response) {
console.log(response);
// set updated value as old value
$(editableObj).attr('data-old_value',editableObj.innerHTML);
$(editableObj).css("background","#FDFDFD");
}
});
}
更新.php
<?php
include "connect.php";
$sql = "UPDATE new_project SET ".$_REQUEST["column"]." = '".$_REQUEST["value"]."' WHERE id= $id ";
mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
?>