Javascript jQuery错误:语法错误,无法识别的表达式:[object HtmlLevel]
我在一组元素中循环,然后我试图在循环中找到该元素的一些特定子元素,但我得到了一个错误 我的代码:Javascript jQuery错误:语法错误,无法识别的表达式:[object HtmlLevel],javascript,jquery,each,Javascript,Jquery,Each,我在一组元素中循环,然后我试图在循环中找到该元素的一些特定子元素,但我得到了一个错误 我的代码: var submenu_height; var secondary_submenus; var secondary_submenu_height; // Get the submenus var submenus = $('#main section.top nav > ul > li > .sub_menu'); // Now loop through each submen
var submenu_height;
var secondary_submenus;
var secondary_submenu_height;
// Get the submenus
var submenus = $('#main section.top nav > ul > li > .sub_menu');
// Now loop through each submenu
submenus.each(function(i, element) {
// Get height of submenu
submenu_height = $(this).height();
// Reset our secondary submenu height
secondary_submenu_height = 0;
// Get submenus of this submenu
secondary_submenus = $(this + ' table.sm_wrapper td ul li .sm_wrapper2');
});
问题在于这一行:
secondary_submenus = $(this + ' table.sm_wrapper td ul li .sm_wrapper2');
我试着使用元素
以及这个
,但都不起作用。我得到的错误是:
Error: Syntax error, unrecognized expression: [object HTMLDivElement] table.sm_wrapper td ul li .sm_wrapper
做我需要的事情的正确方法是什么?你可能想要
secondary_submenus = $(this).find('table.sm_wrapper td ul li .sm_wrapper2');
出现错误的原因是,您试图将对象(this
)添加到字符串并将其用作选择器,因此
…无法识别的表达式:[object HtmlLevel]
要做的是从
$(this)
的上下文中搜索子项,以查找传递的选择器中提到的元素ahhh,是的,我想这可能是我的问题lol。感谢提供有关如何执行此操作的代码。