2014-09-05 77 views
2

我现在只是在Chrome的控制台中。我创造了这个变量:SyntaxError:非法返回声明 - 在url中搜索字符串

url = window.location.href 

这给:

网址 “http://www.example.com/trips/dest/australia-and-south-pacific/cntry/fiji/

现在,我想这一点:

if (url.indexOf('australia-and-south-pacific') > 0) {return 'foo';} 

其中返回:

SyntaxError: Illegal return statement 

我希望控制台返回'foo'。

这是怎么发生的?我注意到收到此错误后,给它几秒钟,并出现一个新的错误:

Uncaught TypeError: Cannot read property 'hide' of undefined 

如果这有助于诊断?

+2

因为你不是在一个函数,所以没有什么回归,也许你想要的东西:'的console.log(“富”)' – 2014-09-05 14:49:03

+0

你不能把一个'return'语句放在一个函数中。 – scrblnrd3 2014-09-05 14:49:14

+0

好的,谢谢,我会更新。对不起,这一定非常简单 – 2014-09-05 14:49:58

回答