返回功能不正常 [英] Return not in function

查看:55
本文介绍了返回功能不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebug报告无功能返回"错误,没有位置(嗯,第1行什么也没有).如何找到此错误的根源?

Firebug is reporting a "return not in function" error with no location (well, line 1 of nothing). How can I track down the source of this error?

return not in function
[Break on this error] return(0)
javascript:return... (line 1)

我在Ubuntu 2.0.0.20的FF上运行FireBug 1.05.

I'm running FireBug 1.05 on FF 2.0.0.20 on Ubuntu.

我找到了一个有效的解决方案(适用于此配置):

I found a solution that works (for this configuration):

  var link = document.createElement('a');
  link.href='/';
  if (childSummary.more) {
    link.onclick = capture(function(id) { follow(id); }, childSummary.id);
  } else {
    link.onclick = capture(function(id) { show(id); }, childSummary.id);
  }
  link.appendChild(document.createTextNode(name));
  div.appendChild(link);

  [...]

 function capture(fn, val) {
   return function() { fn(val); return false; };
 }

代码处于一个循环中,其中id发生了变化,因此需要捕获功能.

The code was in a loop in which the id was changing, necessitating the capture function.

以前,href是'javascript:return 0',并且catch函数没有直接返回false,而是使用fn的结果,并且当它返回等于true时存在一条路径.正在评估href导致错误.

Formerly the href was 'javascript: return 0' and the capture function wasn't returning false directly, instead using the result of the fn, and there was a path when it was returning the equivalent of true. The href was being evaluated causing the error.

将href定义为#"或''会导致所有链接显示为已被访问.根本没有定义href导致没有链接突出显示.这似乎最简单.

Defining href as '#' or '' caused all the links to appear as already visited. Not defining href at all caused there to be no link highlighting. This seemed simplest.

推荐答案

我认为"javascript:return ..."正在说明问题.我相信您正在尝试在锚点的href属性中返回值,如下所示:

I think the "javascript:return ..." is telling. I believe you're trying to return a value in the href attribute of an anchor, as below:

<a href="javascript: return false">Test</a>

Firebug不会告诉您位置的原因是因为它不在任何JavaScript中,而是在DOM的单行代码中.

The reason Firebug isn't telling you the location is because it's not in any JavaScript, but is rather in a one-liner in the DOM.

这篇关于返回功能不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆