현재 에피소드라는 정보 용 테이블이 있습니다. 표에는 제목, 방송 날짜, 에피소드 번호 및 음모로 구성된 필드가 있습니다. 나는 필드를 복제하고 그들을 삭제하는 자바 스크립트를 사용합니다. 내 문제는 삭제 기능은 제목, airdate 및 에피소드 번호 만 삭제하는 것입니다. 그러나 플롯 상자는 그대로 유지됩니다. 내가 말할 수있는 문제는 줄거리가 다른 <tr></tr>
태그에 싸여 있다는 것입니다. 두 세트를 삭제하는 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>
에게있는 자바 스크립트입니다
// Delete the "-" button in first row
$('#attachments tr:first-child .commands a[rel="delete"]').remove();
}
function items_add()
{
obj = $('#template tr').clone().appendTo('#attachments');
lines++;
if (arguments.length > 0) {
options = arguments[0];
$('.title', obj).val(options.title);
$('.airdate', obj).val(options.airdate);
$('.season', obj).val(options.season);
$('.number', obj).val(options.number);
$('.plot', obj).val(options.plot);
}
}
$('#attachments').delegate('.commands a', 'click', function()
{
var action = $(this).attr('rel');
var confirm_delete = true;
// Add action
if ('add' == action) {
items_add();
}
// Delete action
if ('delete' == action) {
// La TR en la tabla
var oTr = $(this).parent().parent();
var episode_name = $('.title', oTr).val();
var episode_airdate = $('.airdate', oTr).val();
var episode_season = $('.season', oTr).val();
var episode_number = $('.number', oTr).val();
var episode_plot = $('.plot', oTr).val();
if (episode_name != '' || episode_number != '' || episode_plot != '') {
if (!confirm('Are you sure you want to delete ' + episode_name + '?')) {
confirm_delete = false;
}
}
if (confirm_delete) {
oTr.remove();
lines--;
}
}
});
$(document).ready(function()
{
items_init();
});
})(jQuery);
당신의 도움이 크게
PHP 마크 업이 아닌 생성 된 HTML 마크 업을 보여 주면 더 쉬울 것입니다. – epascarello
'oTr.remove();를'oTr.next(). remove();로 변경하려고 시도 했습니까? oTr.remove();'? – Prusse
ID 사용에 대해 생각해 보셨습니까? r _ ### _ 1과 r _ ### _ 2를 행에 추가하면 (### = 숫자 ID) 그 ID를 분리하여 한 번에 삭제할 수 있습니다. –