这是我的代码,我试图删除一行并添加一个新的。它从数据库中删除记录,删除记录后我想显示保留数据并删除表中的特定行。但它似乎不合适。请帮助一些人
<?php for($i=0; $i<$this->labNumber; $i++):
$divlabcapdisp="divlabcap_".$i;
$divlabcoursedispdisp="divlabcoursedisp_".$i;
?>
<div class="form-group clone_field_2">
<div class="content-div">
<div class="col-sm-1">
<label class="control-label">Lab <?=$i+1?></label>
</div>
<div class="col-sm-2">
<?=$this->deliverelement($this->labElement[$i])?>
</div>
<div class="col-sm-3">
<?=$this->deliverelement($this->labtypeElement[$i])?>
</div>
<div class="col-sm-2">
<div style="display:<?php if($this->$divlabcapdisp==OT_YES):?>inline<?php else:?>none<?php endif;?>">
<?=$this->deliverelement($this->labcapElement[$i])?>
</div>
</div>
<div class="col-sm-3">
<div style="display:<?php if($this->$divlabcoursedispdisp==OT_YES):?>inline<?php else:?>none<?php endif;?>">
<?=$this->deliverelement($this->labcourseElement[$i])?>
</div>
</div>
<div class="col-sm-1 text-red" <?php if($i==0):?>style="display:none;"<?php endif;?>>
<i class="fa fa-fw fa-trash-o fa-lg" onClick="deleteButton1(this,'clone_field_2')"></i>
</div>
</div>
</div>
并且onclick函数是
function deleteButton1(link,clonefield)
{
var rowCount = $('.'+clonefield).length;
var minCount = 1;
if(rowCount > minCount)
{
$(link).closest('.'+clonefield).remove();
}
else
{
alert("You cannot delete the last row");
}
}
答案 0 :(得分:1)
nearest()适用于祖先树你要找的是 parent()
替换此
if(rowCount > minCount)
{
$(link).closest('.'+clonefield).remove();
}
与
if(rowCount > minCount)
{
$(link).parent('div').parent('div').fadeOut(200, function() { $(link).remove(); });
}