[英]JQuery display concatenated list of text from visible HTML table cells
I have a simple table. 我有一张简单的桌子。 In the first td
in each row, there is a farmer's name (eg, "farmer1", "farmer2", etc.). 在每行的第一个td
中,有一个农民的名字(例如,“ farmer1”,“ farmer2”等)。 So, each row represents information on a different farmer. 因此,每一行代表不同农民的信息。 Suppose that for some valid reason some of the rows are hidden. 假设出于某些正当原因,某些行被隐藏了。 At any given time, I want to be able to show a list of the farmers that are visible in the table. 在任何给定时间,我希望能够显示表中可见的农民列表。
For example, if the state of my table looks like this 例如,如果我的表格状态如下所示
Farmer # | apple | orange | pear
farmer2 | 0 | 1 | 1
farmer3 | 0 | 1 | 0
farmer4 | 0 | 1 | 0
I want to have a link that, when clicked, will toggle the visibility of the following string (text) on an area of the page: 我想要一个链接,当单击该链接时,它将在页面区域上切换以下字符串(文本)的可见性:
farmer2 farmer3 farmer4
Here is an almost fully functional solution: jsfiddle.net/8aszmfkq/2/ 这是一个几乎全功能的解决方案: jsfiddle.net/8aszmfkq/2/
The part I can't figure out is how to extract the text in the first td
of each visible row, concatenate the extracted text, and write the concatenated text to a div. 我无法弄清的部分是如何在每个可见行的第一个td
中提取文本,将提取的文本连接起来,然后将连接的文本写入div。 (If you remove the JS call to updateFarmerList()
, you can see that the toggle works... the problem is really extracting and concatenating.) (如果删除对updateFarmerList()
的JS调用,则可以看到该切换起作用了……问题实际上是提取和连接。)
TypeError: this.text is not a function TypeError:this.text不是函数
Please correct $(this.text())
to $(this).text()
请更正$(this.text())
为$(this).text()
updated fiddle: http://jsfiddle.net/8aszmfkq/3/ 更新的提琴: http : //jsfiddle.net/8aszmfkq/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.