【发布时间】:2017-04-16 09:10:20
【问题描述】:
我有一个带有编辑按钮的 HTML 表格。单击编辑按钮时,它允许该行变为可编辑。现在整行都是可编辑的,但是,我希望 MR_ID 行不可编辑。我怎样才能做到这一点?我在我的代码中尝试了一些东西,但它似乎不起作用。
如果我需要提供更多代码,请告诉我,我会提供的。
这是我的 if 语句的开头,我认为问题应该是:
$(document).on("click", "#html_master .edit", function () {
var $this = $(this);
var tds = $this.closest('tr').find('td').filter(function () {
return $(this).find('.edit').length === 0;
});
if ($this.val() === 'Edit') {
$this.val('Save');
if($this.id != '.mr_id'){
tds.prop('contenteditable', true);
}
}
表格的 HTML/PHP:
<?php
/* Foreach loop that brings in information to populate table */
foreach ($dbh->query($sql) as $rows){
?>
<tr id="<?php echo intval ($rows['MR_ID'])?>">
<td class="mr_id" id="<?php echo intval ($rows['MR_ID'])?>" contenteditable="false"><?php echo intval ($rows['MR_ID'])?></td>
<td class="mr_name" id="mr_name-<?php echo intval ($rows['MR_ID'])?>" name="field" contenteditable="false"><?php echo $rows['MR_Name']?></td>
<td class="buyer_id" id="buy_id<?php echo intval ($rows['MR_ID'])?>" contenteditable="false"><?php echo $rows['Buyer_ID']?></td>
<td class="poc_n" id="poc_n-<?php echo intval ($rows['MR_ID'])?>" contenteditable="false"><?php echo $rows['MR_POC_N']?></td>
<td class="poc_e" id="poc_e-<?php echo intval ($rows['MR_ID'])?>" contenteditable="false"><?php echo $rows['MR_POC_E']?></td>
<td class="poc_p" id="poc_p-<?php echo intval ($rows['MR_ID'])?>" contenteditable="false"><?php echo $rows['MR_POC_P']?></td>
<td><input type="button" class="edit" name="edit" value="Edit">
</tr>
<?php
}
?>
【问题讨论】:
-
什么是
$this。如果它是一个 jquery 对象,那么你不能通过.id获取 id 看起来你也可以与一个类进行比较,它不应该只是'mr_id'(没有前导点) -
我在 javascript 中添加了一些额外的代码来帮助您了解
$this是什么 -
当您单击编辑时,您是否希望每个
td但mr_id都可编辑? -
是的,没错
标签: javascript php html html-table contenteditable