jQuery('td[class=bgoff]').each(function() {
    var td = jQuery(this);
    ... no apply selector to "this" only
});

我正在使用html中的表格数据并尝试解析每个TD的内容(它们不是唯一可识别的)。

使用XPath,我可以添加“this”的路径。另外选择。

如何使用jQuery实现这一目标?

有帮助吗?

解决方案

使用jQuery,您可以选择在选择器表达式之后提供第二个参数,这将成为jQuery用于限制查找范围的上下文。了解更多信息此处

其他提示

如果您已经有一个想要搜索的jquery对象,也可以使用.find(expression)。

在你的例子中:

jQuery('td[class=bgoff]').each(function() {
    var td = jQuery(this);
    $(td).find( <selector to search within td> );
});

来自 jQuery source

// HANDLE: $(expr, context)  
// (which is just equivalent to: $(context).find(expr)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top