简体   繁体   English

我如何使用javascript获取Tr中的值

[英]how can I get a value inside Tr using javascript

How can I get "Test2" using JavaScript? 如何使用JavaScript获得“ Test2”?

Here is my HTML: 这是我的HTML:

<table>
  <th> </th>
  <tr id = "123">
    <td>
      <UL> 
        <Li> Test1 </Li>
        <Li> <a class ="SomeClass" >Test2 <a/> </Li>
      </UL>
    </td>
  </tr>
</table>

You can use document.getElementsByClassName : 您可以使用document.getElementsByClassName

var a = document.getElementsByClassName('SomeClass');
var value = a[0].innerHtml;

JSFiddle 的jsfiddle

If you are already using jQuery you can simply use 如果您已经在使用jQuery,则只需使用

$('.SomeClass').text();

Hope this helps! 希望这可以帮助!

Try the following JavaScript code to do it. 请尝试以下JavaScript代码来实现。

 var example = document.getElementById('test2').innerHTML; alert(example); 
 <table> <th></th> <tr id="123"> <td> <UL> <Li>Test1</Li> <Li> <a class="SomeClass" id="test2">Test2 <a/> </Li> </UL> </td> </tr> </table> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示表格内的文本框值,我想显示一个 <tr> 一次处于戒备状态? 使用JavaScript - How to show the textbox value which is inside table, I want to show the one <tr> at a time in alert? using javascript 使用Javascript,如何显示 <tr> 在另一个之上 <tr> 悬停时,隐藏第二个 <tr> ? - Using Javascript, how can I show a <tr> on top of another <tr> on hover, hiding the second <tr>? 如何使用javascript获取tr标签和td值中的特定参数 - How to get specific parameter in tr tag and td value using javascript 如何使用javascript或打字稿在表中获取tr的第二个td值 - How to get second td value of tr in a table using javascript or typescript 如何从最接近的“ tr”的第n个元素中获取值? - how can I get a value from the nth element of the closest 'tr'? 如何使用javascript选择嵌套在表的tbody内的tr内的所有锚标记href URL - how can I select all anchor tag href URL that is nested inside a tr inside tbody of a table with javascript 我如何使用jQuery的JavaScript获取ListView项目模板内的隐藏字段值 - How can i get the hidden field value inside a listview item template using javascript of jquery 如何使用JavaScript将gridview中的复选框值获取到texbox中? - How can I get checkbox value inside gridview into texbox using javascript? 如何在jsp中获取Javascript函数的值? - How can i get value of Javascript function, inside jsp? 如何使用javascript获取div内的div值? - How do I get the value of a div inside a div using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM