2012-06-25 4 views
2

내 질문은 어쩌면 조금 불분명 현재 선택 후 요소를 얻는어떻게 내가 예를 들어 줄 것이다 있도록

<table id="products"> 
     <tr id="P1" class="A1"><td>1x</td><td>Product 1</td><td>&euro; 9,50</td><td><a href="#">(x)</a></td></tr> 
     <tr id="P2" class="A1"><td>1x</td><td>Product 2</td><td>&euro; 10,50</td><td><a href="#">(x)</a></td></tr> 
    </table> 

내가 뭘 달성하려는 것은

$('#bestelling tr').each(function(index) { 
     var naam = $(this + " td + td").text(); 
     var id = $(this).attr('id'); 
     alert(id + " " + naam); 
    }); 

사람을합니까 일할 수있는 다음과 같은 기능입니다 내가 어떻게이 일을 할 수 있는지 알고 있니? 문제에 대한 나의 간단한 설명에 대해 유감스럽게 생각한다. 나의 영어는 그렇게 좋지 않다. 빠른 반응

답변

1
$('#bestelling tr td:eq(1)').each(function(index) { 
    var naam = $(this).text(); 
    var id = this.id; 
    alert(id + " " + naam); 

    // The tr is: 
    $(this).parent() 
    // Or the DOM element: 
    this.parentNode 
}); 
+0

감사합니다, 내가 각을 사용하지 않지만 다시 클릭 TR에게 – user1169526

+0

을 처리 할 나중에 "이"키워드와 함께이 작업을 수행 할 수있는 방법이있다! ': eq (1)'++ 1. –

+0

@ user1169526 tr은 간단히 :'$ (this) .parent()' – gdoron

0
here you go mate. Run the code below: 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
     "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title>How to get element after current selector</title> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $('table tr').click(function (e) { 
       var naam = ""; 
       $(this).children().each(function() { 
        naam += $(this).html() + ' '; 
       }); 

       alert(naam); 
      }); 

     }); 
    </script> 

</head> 
<body> 
<table id="products"> 
    <tr id="P1" class="A1"> 
     <td>1x</td> 
     <td>Product 1</td> 
     <td>&euro; 9,50</td> 
     <td><a href="#">(x)</a></td> 
    </tr> 
    <tr id="P2" class="A1"> 
     <td>1x</td> 
     <td>Product 2</td> 
     <td>&euro; 10,50</td> 
     <td><a href="#">(x)</a></td> 
    </tr> 
</table> 

</body> 
</html> 
+0

이 질문에 어떻게 대답 할 수 없습니까? 조금도! – gdoron

+0

@ gdoron 당신이 대답을 알고있는 코드를 읽고 이해할 수 있다면, 그 simnple. – haroonxml

+0

OK 질문에 대답한다고 생각하면 논쟁하지 않을 것입니다. – gdoron