我得到这个错误! [函数外的'return'语句] [英] I get this error! [ 'return' statement outside of function ]
问题描述
我正在为一个客户端创建一个表单验证器,并在Internet Explorer(Explorer)7/8 ...中遇到了这个 only 奇怪的错误.
I was creating a form validator for a client and ran into this weird error only in Internet Explorer (Explorer) 7/8....
在函数第1行,字符1之外的'return'
'return' outside of function, line 1, char 1
当然,第1行没有任何代码.这是一条简单的注释语句.而且没有任何扭曲的方式.所以我知道这只是一个调试错误的方向.
Of course, there was no code whatsoever on line 1. It was a simple commented statement. And there was nothing wring with it in any way. So I knew it was just a debug misdirection.
我一直在拔头发,以了解这里可能出什么问题...
I have been pulling my hair out to understand what could be wrong here...
我已经排除了显而易见的情况:循环中的return语句,单个函数中的return语句太多,以及实际上在合法函数定义之外的所有return.
I have already ruled out the obvious: return statements in a loop, too many return statements in a single function, and any returns actually outside of a legitimate function definition.
这是什么原因?
推荐答案
问题是我正在使用return语句覆盖表单的默认行为,并将其分配给属性 but 它没有放在匿名函数中!
The problem was that I was using a return statement to override the default behavior for my form and it was assigned to a property, but it was not placed inside an anonymous function!
我有一个这样设置的表单元素:
I had a form element that was set up like this:
<form name="formname" onSubmit="javascript:validateForm(this);" action="javascript:return false;" method="post" enctype="multipart/form-data">
我需要更改的只是action属性:
All I needed to change was the action property to this:
… action="javascript:function(){return false};"
它现在可以完美地工作了!
It now works flawlessly!
这篇关于我得到这个错误! [函数外的'return'语句]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!