`find()`undefined不是一个函数

编程入门 行业动态 更新时间:2024-10-21 20:24:49
本文介绍了`find()`undefined不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个小jquery函数:

I have this little jquery function:

$.each($('#TableBody tr:gt(0)'), function(index, element){ element.find('td').last().html($('<span/>', {class: "input-group-addon", text: 'Auswählen'})); });

不知怎的,我在第一行收到此错误:

Somehow i get this error in the first line:

Uncaught TypeError: undefined is not a function

我在控制台中试了一些东西来解决这个问题!但不知何故没有用!

I tried some things in the console to fix this problem! But somehow nothing worked!

现在我希望你能帮助我! JSFIDDLE: jsfiddle/3C98M/

Now i hope you can help me! JSFIDDLE: jsfiddle/3C98M/

谢谢

推荐答案

元素不是jQuery对象, $的第二个参数。每个函数返回本机DOM节点

element is not a jQuery object, the second argument of the $.each function returns the native DOM node

$.each($('#TableBody tr:gt(0)'), function(index, element){ $(element).find('td').last().html($('<span/>', {"class": "input-group-addon", text: 'Auswählen'})); });

另请注意 class 是保留关键字在javascript中应该引用。 它也可以写成

Also note that class is a reserved keyword in javascript and should be quoted. It could also be written

$('#TableBody tr:gt(0)').each(function(index, element) { $(element).find('td').last().html( $('<span/>', { "class" : "input-group-addon", text : 'Auswählen' }) ); });

这是更具可读性的IMO。

which is more readable IMO.

更多推荐

`find()`undefined不是一个函数

本文发布于:2023-10-30 04:16:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:一个函数   find   undefined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!