你好evey主体我在jquery中有探针,我需要删除tr表格表 我在单击按钮时删除第一个tr中的工作(由HTML添加的第一个tr) 但没有删除(由jquery添加了anttr)
节点:对于jquery添加的项目,删除根本不起作用
此代码表
<table class="table table-bordered table-striped sub-table victim-table">
<thead>
<tr>
<th> الاسم</th>
<th> الرقم المدني</th>
<th> تاريخ الميلاد</th>
<th> الجنسية </th>
<th> الجنس </th>
<th> الحالة</th>
<th> <span class="btn btn-success btn-sm add-victim-row"> <i class="fa fa-plus"></i> </span></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="form-control" id="victim_name" name="victim_name[]" autocomplete="off">
</td>
<td>
<input type="text" class="form-control" id="victim_id" name="victim_id[]" autocomplete="off">
</td>
<td>
<input type="text" class="form-control" id="victim_dob" name="victim_dob[]" autocomplete="off">
</td>
<td>
<select name="victim_national_id[]" id="victim_national_id" class="form-control">
<option value="">....</option>
@foreach($national as $key => $n)
<option value="{{ $n->id }}" {{ $n->id == 1 ? 'selected' : '' }}>{{ $n->national }}</option>
@endforeach
</select>
</td>
<td>
<div class="form-group">
<label>
ذكر:<input type="radio" value="1" name="sex[]" class="minimal">
</label>
<label>
انثي: <input type="radio" value="0" name="sex[]" class="minimal">
</label>
</div>
</td>
<td>
<div class="form-group">
<label>
عشير:<input type="radio" value="1" name="ashir[]" class="minimal">
</label>
<label>
غير عشير:<input type="radio" value="0" name="ashir[]" class="minimal">
</label>
</div>
</td>
{{--<td></td>--}}
<td><span class="btn btn-danger btn-sm victim-remove-row"><i class="fa fa-times"></i></span></td>
</tr>
</tbody>
</table>
此代码通过jquery添加tr
<script type="text/javascript">
/*start victim */
$('.add-victim-row').on('click', function () {
addVictimRow();
})
function addVictimRow() {
var tr = '<tr>' +
'<td>' +
'<input type="text" class="form-control" id="victim_name" name="victim_nam[]" autocomplete="off">' +
'</td>' +
'<td>' +
'<input type="text" class="form-control" id="victim_id" name="victim_id[]" autocomplete="off">' +
'</td>' +
'<td>' +
'<input type="text" class="form-control" id="victim_dob" name="victim_dob[]" autocomplete="off">' +
'</td>' +
'<td>' +
'<select name="victim_national_id" id="victim_national_id[]" class="form-control">' +
'<option value="">....</option>' +
'@foreach($national as $key => $n)' +
'<option value="{{ $n->id }}" {{ $n->id == 1 ? 'selected' : '' }}>{{ $n->national }}</option>' +
'@endforeach' +
'</select>' +
'</td>' +
'<td>' +
'<div class="form-group">' +
'<label>' +
' ذكر:<input type="radio" value="1" name="sex[]" class="minimal">' +
'</label>' +
'<label>' +
' انثي: <input type="radio" value="0" name="sex[]" class="minimal">' +
'</label>' +
'</div>' +
'</td>' +
'<td>' +
'<div class="form-group">' +
'<label>' +
' عشير:<input type="radio" value="1" name="ashir[]" class="minimal">' +
'</label>' +
'<label>' +
'غير عشير:<input type="radio" value="0" name="ashir[]" class="minimal">' +
'</label>' +
'</div>' +
'</td>' +
'<td><span class="btn btn-danger btn-sm victim-remove-row"><i class="fa fa-times"></i></span></td>' +
'</tr>';
$('.victim-table tbody').append(tr)
}
此代码删除tr
//delete victim
$('.victim-remove-row').on('click', function () {
$(this).parent().parent().remove();
});