此代码中的第二个语句:
var $this = $(this).children('div.submenu1').children('a.subtile')[0],
title = $this.text(),
name = $this.attr('node').val;
Run Code Online (Sandbox Code Playgroud)
产生此错误:
Uncaught TypeError: $this.text is not a function
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停$this.text()在Chrome调试器中时,我可以看到我想要的值title.
我该如何解决这个错误?
Utk*_*nos 13
发生这种情况是因为您将变量分配给本$this机DOM引用,而不是jQuery引用.只有后者才能访问jQuery API.
你是通过"到达内部"类似于数组的jQuery堆栈并通过提取本机引用来实现的[0].失去这个,它会起作用:
var $this = $(this).children('div.submenu1').children('a.subtile'),
title = $this.text(), //<-- now has access to jQuery API
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10818 次 |
| 最近记录: |