어떠하호
271
2019-03-22 14:24:32
3
331

table tr의 특정 td클릭 시 해당 tr index와 td데이터를 가져오고 싶습니다.



<table id="curriculumList" class="sortable"><thead><tr><th>번호</th> <th>제목</th> <th>학습요소명</th> <th></th> <th></th> <th></th> <th>삭제</th></tr></thead> <tbody id="tbody1" draggable="true" class="ui-sortable"><tr><td name="num" class="num">1</td> <td onclick="fn_pagemove()" target="_blank" style="cursor: pointer;">
                                                수강제목0
                                            </td> <td style="cursor: move;"><span>
                                                    e러닝
                                                </span> <!----></td> <td style="cursor: move;"><span><a href="#" onclick="fn_OpenCalendar(this)" class="modal-calendar-page" style="text-decoration: none;"><i aria-hidden="true" class="fa fa-calendar fa-2x" style="cursor: pointer; color: black;"></i></a></span> <!----></td> <td style="cursor: move;"><span>
                                                    수강 <br>
                                                    열람
                                                </span> <!----></td> <td style="cursor: move;"><!---->
                                                    2019-02-01 ~ 2019-02-28 <br>
                                                    2019/03/01 ~  2019-03-31
                                                <!----></td> <td style="cursor: move;"><a href="#" data-mv-delete-page-title="A000017X" onclick="rowDelete(this)" class="modal-delete-confirm"><img src="images/icn_delete01.png" alt="delete" style="cursor: pointer;"></a></td></tr><tr class="" style=""><td name="num" class="num">2</td> <td onclick="fn_pagemove()" target="_blank" style="cursor: pointer;">
                                                 수강제목0
                                            </td> <td style="cursor: move;"><span>
                                                    e러닝
                                                </span> <!----></td> <td style="cursor: move;"><span><a href="#" onclick="fn_OpenCalendar(this)" class="modal-calendar-page" style="text-decoration: none;"><i aria-hidden="true" class="fa fa-calendar fa-2x" style="cursor: pointer; color: black;"></i></a></span> <!----></td> <td style="cursor: move;"><span>
                                                    수강 <br>
                                                    열람
                                                </span> <!----></td> <td style="cursor: move;"><!---->
                                                    2019-02-01 ~ 2019-02-28 <br>
                                                    2019/03/01 ~  2019-03-31
                                                <!----></td> <td style="cursor: move;"><a href="#" data-mv-delete-page-title="A000018E" class="modal-delete-confirm"><img src="images/icn_delete01.png" alt="delete" style="cursor: pointer;"></a></td></tr><tr class="" style=""><td name="num" class="num">3</td> <td onclick="fn_pagemove()" target="_blank" style="cursor: pointer;">
                                                수강제목2
                                            </td> <td style="cursor: move;"><span>
                                                    e러닝
                                                </span> <!----></td> <td style="cursor: move;"><span><a href="#" onclick="fn_OpenCalendar(this)" class="modal-calendar-page" style="text-decoration: none;"><i aria-hidden="true" class="fa fa-calendar fa-2x" style="cursor: pointer; color: black;"></i></a></span> <!----></td> <td style="cursor: move;"><span>
                                                    수강 <br>
                                                    열람
                                                </span> <!----></td> <td style="cursor: move;"><!---->
                                                    2019-02-01 ~ 2019-02-28 <br>
                                                    2019/03/01 ~  2019-03-31
                                                <!----></td> <td style="cursor: move;"><a href="#" data-mv-delete-page-title="A000018B"  class="modal-delete-confirm"><img src="images/icn_delete01.png" alt="delete" style="cursor: pointer;"></a></td></tr></tbody></table>

이화면이 아래 처럼 보이는데요

onclick에서 rowDelete 함수를 호출해서 행데이터를 삭제하고 있습니다.

 $(obj2).parent().parent().remove();

만약에 1행의 delete를 클릭하면 1행이 삭제되긴 하는데 삭제되는 부분에서 

해당 행을 클릭한 데이터를 가져오고 싶은데 어떻게 해야될까요?

번호의 1을 가져오고 싶습니다.!

0
0
  • 답변 3

  • 어쩌다
    5k
    2019-03-22 14:32:55

    $(obj2).parent().parent().find("td:first").text()

    2
  • EastGlow
    1k
    2019-03-22 14:36:50 작성 2019-03-22 14:37:48 수정됨

    function rowDelete(obj){

         var $number = $(obj).parent().siblings('.num').text();

    }


    이렇게하면 될 거 같은데 한번 해보시겠어요? 아니면 윗분이 달아주신 게 제일 간단하긴 합니다.

    1
  • 어떠하호
    271
    2019-03-22 14:39:49

    답변주신 두분 감사합니다.!!

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.