2012-04-19 6 views
0

현재 에피소드라는 정보 용 테이블이 있습니다. 표에는 제목, 방송 날짜, 에피소드 번호 및 음모로 구성된 필드가 있습니다. 나는 필드를 복제하고 그들을 삭제하는 자바 스크립트를 사용합니다. 내 문제는 삭제 기능은 제목, 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); 

당신의 도움이 크게

+1

PHP 마크 업이 아닌 생성 된 HTML 마크 업을 보여 주면 더 쉬울 것입니다. – epascarello

+0

'oTr.remove();를'oTr.next(). remove();로 변경하려고 시도 했습니까? oTr.remove();'? – Prusse

+0

ID 사용에 대해 생각해 보셨습니까? r _ ### _ 1과 r _ ### _ 2를 행에 추가하면 (### = 숫자 ID) 그 ID를 분리하여 한 번에 삭제할 수 있습니다. –

답변

1

C를 이해할 수있을 것이다

$rand = time() * rand(); 

가 L에 에코 PHP에서

같은 난수를 생성이 행

var oTr = $(this).parent().parent(); 

에 hange
var oTr = $(this).closest("tr"); 

그럼 oTr.remove()

1

IDEA 사용 오프라인 행

<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(); 

아이디어는 라인과 2 호선 클래스와 TR을 식별 할 수있는 고유 한 문자열을 가지고있다

+0

위의 내 의견은 꽤 많이 있지만 데이터 속성을 사용하고 있습니다. 다른 프로세스에서 직접 개별 트렁크를 대상으로 지정해야하는 경우가 아니라면 ID 경로가 도움이 될 수 있습니다. @ 크레이그 –

관련 문제