문제

I have a table like this-

<table>
 <tr>
   <td>
      <label id="lbl1" value="1">Label1</label>
   <td> 
   <td>
     Some data
   </td>
   <td>
     Some data
   </td>
 </tr>
 <tr>
   <td>
      <label id="lbl2" value="1">Label1</label>
   <td> 
   <td>
     Some data
   </td>
   <td>
     Some data
   </td>
 </tr>
 <tr>
   <td>
      <label id="lbl3" value="1">Label1</label>
   <td> 
   <td>
     Some data
   </td>
   <td>
     Some data
   </td>
 </tr>
</table>

My problem is that I want to alert the value of label present in the second row's first column. Assume that I don't know label id means I know its pattern like lbl1,lbl2 or lbl3.. but not exactly what it is in the second row.

도움이 되었습니까?

해결책

If you are okay to use jQuery use this fiddle

var label = $('table tr:eq(1) td:eq(0)').find("label").attr("value")
alert(label);

다른 팁

You can use something like next

var labels = document.getElementsByTagName("label");
for (var i=0; i<labels.length; i++)
   if (labels[i].id && labels[i].id.indexOf("lbl") == 0){
      //you have found the label in the first row
   }

You Can get label value by class name

$("label[class=lblclass]").each(function() {var result= $(this).val(); });

(OR) You can get the Particular Label Value by ID

function getlabel_value(){var result=$('#lbl1').val();}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top