使用Javascript删除表行
目前,我有一个名为“剧集”的信息表。该表包含由标题、播放日期、集号和情节组成的字段。我使用javascript克隆字段并删除它们。我的问题是删除功能只删除标题、播放日期和剧集编号;但是,绘图框仍然存在。从我所能看出的问题是,绘图被包装在不同的使用Javascript删除表行,javascript,jquery,html-table,Javascript,Jquery,Html Table,目前,我有一个名为“剧集”的信息表。该表包含由标题、播放日期、集号和情节组成的字段。我使用javascript克隆字段并删除它们。我的问题是删除功能只删除标题、播放日期和剧集编号;但是,绘图框仍然存在。从我所能看出的问题是,绘图被包装在不同的标记中。如何使用delete函数删除这两个集合 这是桌子 <table id="template" style="display: none"> <tr class="line"> <td width="50%">
标记中。如何使用delete函数删除这两个集合
这是桌子
<table id="template" style="display: none">
<tr class="line">
<td width="50%">
<label><?php _e('Episode Title'); ?></label>
<p>
<input type="text" name="episode_title[]" id="episode_title[]" value="" class="title regular-text" style="width:100%;" />
</p>
</td>
<td width"10%">
<label><?php _e('Airdate'); ?></label>
<p>
<input type="text" name="episode_airdate[]" id="episode_airdate[]" value="" class="airdate regular-text" style="width:100%" />
</p>
</td>
<td width="10%">
<label><?php _e('Season:'); ?></label>
<p>
<?php
for($i=1; $i<=50; $i++)
$season_nums[]=$i;
echo '<select name="episode_season[]" select id="episode_season[]" class="season regular-text" style="100%">';
echo '<option value="">' . __("Season" ) . '</option>';
foreach($season_nums as $season_num){
$selected = '';
echo '<option value="' . $season_num . '" ' . $selected . '>' . $season_num . '</option>';
}
echo '</select>';
?>
</p>
</td>
<td width="10%">
<label><?php _e('Episode:'); ?></label>
<p>
<input type="text" name="episode_number[]" id="episode_number[]" value="" class="number regular-text" style="width: 100%" />
</p>
</td>
<td width="10%" class="commands">
<a rel="delete" class="button">-</a> <a rel="add" class="button">+</a>
</td>
</tr>
<tr class="line2">
<td width="100%">
<label><?php _e('Plot:'); ?></label>
<textarea name="episode_plot[]" id="episode_plot[]" class="plot regular-text"value="" cols="100%" rows="10" tabindex="4" ><?php echo $_POST['episode_season'] ?></textarea>
</td>
</tr>
非常感谢您的帮助更改此行
var oTr = $(this).parent().parent();
到
然后使用oTr.remove()
在php中,生成一个随机数,如
$rand = time() * rand();
在行上回显它
<tr class="line" data-row="<?php echo $rand; ?>">
想法是使用一个唯一的字符串来识别带有line和line2类的tr如果显示生成的html标记而不是php标记,会更容易。是否尝试更改oTr.remove()代码>到oTr.next().remove();oTr.remove()代码>?您考虑过使用ID吗?将say r###################u one和r#########u two添加到行(其中###<代码>$('r#u'+id+'u one')。删除()代码>等…@Prusse谢谢你为我工作me@Yaypaul我喜欢这个想法,我可能会实现它以防止进一步的麻烦,非常感谢我在上面的评论,但使用数据属性。它也会很好地工作,除非您需要直接将单个tr作为其他进程的目标,否则ID路由可能会对您有更多帮助@克雷格
$rand = time() * rand();
<tr class="line" data-row="<?php echo $rand; ?>">
<tr class="line2" data-row="<?php echo $rand; ?>">
var oTr = $(this).closest("tr");
var data-row =$(oTr).attr('data-row');
$('tr[data-row=' + data-row + ']').remove();