jQuery从特定行中选择文本
使用下表:jQuery从特定行中选择文本,jquery,Jquery,使用下表: <table id="languages" border="0" cellspacing="1"> <thead> <tr> <th>Language</th> <th>Type</th> <th>Invented</th> </tr> </thead> <tbody> <
<table id="languages" border="0" cellspacing="1">
<thead>
<tr>
<th>Language</th>
<th>Type</th>
<th>Invented</th>
</tr>
</thead>
<tbody>
</tr>
<tr>
<td>Ruby</td>
<td>Dynamic</td>
<td>1993</td>
</tr> <table id="languages" border="0" cellspacing="1">
<thead>
<tr>
<th>Language</th>
<th>Type</th>
<th>Invented</th>
</tr>
</thead>
<tbody>
<tr>
<td>Java</td>
<td>Static</td>
<td>1995</td>
<tr>
<td>Smalltalk</td>
<td>Dynamic</td>
<td>1972</td>
</tr>
<tr>
<td>C++</td>
<td>Static</td>
<td>1983</td>
</tr>
</tbody>
</table>
谢谢请使用
$('#languages tr:eq(3)').text()
获取全文
及
获取一系列文本:[Smalltalk,Dynamic,1972]
但请注意,您的html有错误,您的行似乎是“languages tr:eq2”,而不是“languages tr:eq3”
将非标准属性放入tr标记:其中键在数据库表中的id,然后选择行和单元格:$'[key=3]'。查找'td'。每个。。。工作样本
在第一次打开之后,您将关闭未打开的表,并且对多个表使用相同的id不是一个好主意,这不会给您提供所需的标记。感谢所有回复。我现在正在尝试一些建议。看起来我复制和粘贴时出错了。
$('#languages tr:eq(3)').text()
$('#languages tr:eq(3) td').map(function(){return $(this).text()}).toArray()
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<table id="languages" border="0" cellspacing="1">
<thead>
<tr>
<th>Language</th>
<th>Type</th>
<th>Invented</th>
</tr>
</thead>
<tbody>
<tr key="1">
<td>Ruby</td>
<td>Dynamic</td>
<td>1993</td>
</tr>
<tr key="2">
<td>Java</td>
<td>Static</td>
<td>1995</td>
</tr>
<tr key="3">
<td>Smalltalk</td>
<td>Dynamic</td>
<td>1972</td>
</tr>
<tr key="4">
<td>C++</td>
<td>Static</td>
<td>1983</td>
</tr>
</tbody>
</table>
<script>
var row = new Array();
$('[key=3]').find('td').each(function(){
row.push($(this).text());
});
alert('' + row);
</script>
</body>
</html>