本文介绍了`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不是一个函数
发布评论