简体   繁体   English

javascript查找html <tr> 与类和嵌套 <td>

[英]javascript find html <tr> with class and with nested <td>

running simple export javscript function for this stackoverflow - Export to CSV using jQuery and html 为此stackoverflow运行简单的导出javscript函数- 使用jQuery和html导出为CSV

example here: http://jsfiddle.net/terryyounghk/KPEGU/ 此处的示例: http : //jsfiddle.net/terryyounghk/KPEGU/

however I want to change it up so it only gets rows that have a certain class, this is what i've tried so far. 但是,我想对其进行更改,以便仅获取具有特定类的行,这是我到目前为止已经尝试过的方法。

original 原版的

var $rows = $table.find('tr:has(td)'),

mine

var $rows = $table.find('tr.hasClass('show'):has(td)'),

I know nothing about JS, apparently, so help is much appreciated. 显然,我对JS一无所知,因此非常感谢您的帮助。

You don't need to use hasClass in selector. 您无需在选择器中使用hasClass Your code should be: 您的代码应为:

var $rows = $table.find('tr.show:has(td)'),

where your class name is show . 您的班级名称show在哪里。 Dot ( . ) in jQuery and CSS means class selector already. jQuery和CSS中的点( . )表示class选择器已经存在。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM