[英]How to get table cell value with javascript by attribute
function getSelectedCopyDates() {
var arr = new Array();
//for every row that has a checked checkbox
$("tr").has(".noteCheckBox:checked").each(function (i) {
if ($(this).id !== "checkAllNotes"){//since this doesn't have a "abbr=..." it breaks the code below "# syntax error"
//push the value of column(FName, LName) into the array
arr.push($("#" + this.id + "> td[abbr='EventDate'] > div").text());
}
});
return arr;
}
Try this 尝试这个
This is to get the text inside td 这是为了获取td内的文本
$('td[abbr="FName, LName"]').text();
OR 要么
$('td[abbr*="FName"][abbr*="LName"]').text();
To get the value Try this 获得价值尝试一下
$('td[abbr*="FName"][abbr*="LName"]').attr('value')
If by "cell value" you're just looking to get the text inside the <td>
then you could do something like this
: 如果通过“单元格值”来查找
<td>
的文本,则可以执行this
:
HTML : HTML :
<table>
<tr>
<td align="center" abbr="FName, LName">RAWR</td>
</tr>
</table>
jQuery : jQuery的 :
$("td[abbr='FName, LName']").text();
You can use jQuery's .text()
method to get the value within the given element. 您可以使用jQuery的
.text()
方法来获取给定元素内的值。
EDIT : 编辑 :
Saw you needed to get only the <td>
s where they contain checkboxes that are checked, so this may work for you: 看到您只需要获取
<td>
,其中包含选中的复选框,因此这可能对您有用:
$("td[abbr='FName, LName'] > input:checked").parent().text();
Find all the td[abbr='FName, LName'
that contain an input that is checked, then get the text of the that elements parent. 找到所有包含已选中输入的
td[abbr='FName, LName'
,然后获取父元素that的文本。
//You won't need the on change event for you code. I only added it here to show you what happens when there are values and when there are no values.
$("input").on("change", function(){
var arr = new Array();
//for every row that has a checked checkbox
$("tr").has(".noteCheckBox:checked").each(function(i){
//push the value of column 5 (FName, LName) into the array
arr.push($("#"+this.id + "> td > div.c5").text());
});
//Print the array to the console.
console.log(arr);
});
EDIT : 编辑 :
your function should be: 您的功能应为:
function getSelectedInvestigatorNames() {
var arr = new Array();
//for every row that has a checked checkbox
$("tr").has(".noteCheckBox:checked").each(function(i){
//push the value of column 5 (FName, LName) into the array
arr.push($("#"+this.id + "> td[abbr='FName, LName'] > div").text());
});
return arr;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.