将当前元素的子文本推送到数组的语法

时间:2017-03-06 21:39:11

标签: jquery

使用jQuery我在循环中当前元素的第四个子元素中选择了文本。

这个选择似乎没问题

 $(this).children().eq(3).text();

但是当尝试将其推送到数组时,此行会出现错误“myArray.push。$ is is a function”:

myArray.push.$(this).children().eq(3).text();

如果添加这样的括号,我会收到错误“SyntaxError:unexpected token(

myArray.push.($(this).children().eq(3).text());

我不能在一条线上做吗?我是否必须为选择设置变量,然后推送变量?

1 个答案:

答案 0 :(得分:1)

首先,myArray.push。($(this).children()。eq(3).text())有一个额外的"。"在推和括号的开头之间。

所以,试试:

myArray.push($(this).children().eq(3).text());