【发布时间】:2016-09-30 14:06:04
【问题描述】:
我有一个包含“编辑/保存”和“删除”按钮的表格。每当我单击“编辑”按钮时,它都会使行可编辑并更改为“保存”按钮,以便我可以保存更改。但是,当我这样做时,它会使每个单元格都可编辑,并且只有第一行的编辑按钮起作用。第二排、第三排等都不起作用
我的问题是两个部分...
如何使行中的某些单元格不可编辑而其他单元格可编辑?我特别希望第一个单元格“MR_ID”不可编辑。
如何让 Edit 功能适用于多行而不是仅适用于第一行?
相关HTML/PHP代码:
<?php
foreach ($dbh->query($sql) as $rows){
?>
<tr>
<td id="mr_id" contenteditable="false"><?php echo intval ($rows['MR_ID'])?></td>
<td id="mr_name" contenteditable="false"><?php echo $rows['MR_Name']?></td>
<td id="buyer_id" contenteditable="false"><?php echo $rows['Buyer_ID']?></td>
<td id="poc_n" contenteditable="false"><?php echo $rows['MR_POC_N']?></td>
<td id="poc_e" contenteditable="false"><?php echo $rows['MR_POC_E']?></td>
<td id="poc_p" contenteditable="false"><?php echo $rows['MR_POC_P']?></td>
<td><button id="edit" name="edit">Edit</button>
<button id="delRow" name="delete" onclick="deleteRow(this)">Delete</button></td>
</tr>
相关Javascript代码:
$(document).ready(function() {
$('#edit').click(function() {
var $this = $(this);
var tds = $this.closest('tr').find('td').filter(function() {
return $(this).find('#edit').length === 0;
});
if ($this.html() === 'Edit') {
$this.html('Save');
tds.prop('contenteditable', true);
} else {
$this.html('Edit');
tds.prop('contenteditable', false);
}
});
});
【问题讨论】:
-
你已经完成了deleteRow(this),你有什么理由没有做editRow(this)?
标签: javascript php jquery html contenteditable