JQuery:传递 $(this).parent();方法?

发布于 2024-08-13 17:44:40 字数 332 浏览 3 评论 0原文

我有一个简单的脚本:

$('.expand').each(function(i){ 
var _Expand = $(this).parent();
    ExpGroupBy(_Expand);
});

尝试通过类“expand”传递所有

但是 firebug 不断弹出错误:

'类型错误: formObj.getElementsByTagName 不是 函数'

有什么想法吗?

谢谢^^

I have a simple script:

$('.expand').each(function(i){ 
var _Expand = $(this).parent();
    ExpGroupBy(_Expand);
});

Trying to pass the <tr> of all <td> with the class 'expand'

However firebug keeps popping up the Error:

'TypeError:
formObj.getElementsByTagName is not a
function'

Any ideas?

Thanks ^^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只怪假的太真实 2024-08-20 17:44:40

只要函数知道参数是 jQuery 对象而不是 DOM 元素本身。如果函数需要 DOM 元素引用,您可以轻松地这样做......

$('.expand').each(function(i){
  var _Expand = $(this).parent();
  ExpGroupBy(_Expand[0]);  // Note the [0]
});

As long as the function understands that the parameter is the jQuery object and not the DOM element itself. If the function expects a DOM element reference, you can easily do that like this...

$('.expand').each(function(i){
  var _Expand = $(this).parent();
  ExpGroupBy(_Expand[0]);  // Note the [0]
});
爱人如己 2024-08-20 17:44:40

parent() 返回一个 jQuery 对象。试试这个:

$(".expand").parent().each(function() { 
    ExpGroupBy(this);
});

parent() returns a jQuery object. Try this instead:

$(".expand").parent().each(function() { 
    ExpGroupBy(this);
});
不即不离 2024-08-20 17:44:40

如果 ExpGroupBy 需要 DOM 元素,请将其调用为 ExpGroupBy(_Expand[0])

If ExpGroupBy expects DOM element call it as ExpGroupBy(_Expand[0])

怼怹恏 2024-08-20 17:44:40

get(0) 返回封装在 jquery 对象中的元素。您也可以使用 _Expand.get(0)

get(0) returns the element encapsulated in jquery object. You can use _Expand.get(0) as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文