2012-01-01 22 views
11

मैं इस तालिकाक्रम में कुछ पेरेंट तत्व आईडी प्राप्त करें जावास्क्रिप्ट समारोह

<table id="tblId"> 
     <thead> 
      <tr> 
       <th>View Name</th> 
       <th>View Description</th>      
      </tr> 
     </thead> 
      <tbody> 
       <tr id="1"> 
        <td>Name</td>      
        <td><span onclick="jsFunction()">description</span></td> 
       </tr> 
       <tr id="2"> 
        <td>Name</td>      
        <td><span onclick="jsFunction()">description</span></td> 
       </tr> 
      </tbody> 
</table> 

प्रत्येक अवधि मैं js कि विशेष पंक्ति की पंक्ति आईडी कार्य करते है, कैसे कर भेजने की जरूरत है की onclick घटना में है करने के लिए भेजने के लिए मैं ऐसा करता हूँ?

धन्यवाद!

उत्तर

22

एक तरह से,

... onclick="jsFunction(this)" .... 

अपने jsFunction में आप टीआर तत्व मिल सकते हैं,

function jsFunction(sender){ 
     var tr = sender.parentNode.parentNode; 
     alert(tr.getAttribute('id')); 
    } 
+10

या बस आप नीचे के रूप में jsFunction साथ भेज सकते हैं "प्रेषक" डेटा है 'tr.id' – dfsq

+0

धन्यवाद आपको बहुत – Ovi

संबंधित मुद्दे