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;
}
最佳答案
如果通过“单元格值”您只是想获取 <td>
内的文本那么你可以做类似 this
的事情:
HTML:
<table>
<tr>
<td align="center" abbr="FName, LName">RAWR</td>
</tr>
</table>
jQuery:
$("td[abbr='FName, LName']").text();
您可以使用 jQuery 的 .text()
方法获取给定元素内的值。
编辑:
看到您只需要获取 <td>
它们包含已选中的复选框,因此这可能适合您:
$("td[abbr='FName, LName'] > input:checked").parent().text();
查找所有td[abbr='FName, LName'
包含已检查的输入,然后获取该元素父元素的文本。
<强> EXAMPLE
//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);
});
<强> UPDATED EXAMPLE
编辑:
你的函数应该是:
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;
}
关于javascript - 如何使用javascript按属性获取表格单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12735018/