对象预期错误 [英] object expected error

查看:64
本文介绍了对象预期错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经有一段时间了,而且我似乎找不到我的代码出了什么问题。我有2个文件一个c3common.js

只包含我的主html页面的javascript函数和我的主要

html页面是test.html。它们当然是一个更大的文件系统的一部分,但我已经将问题追溯到代码减少了部分代码。页面加载完全正常然而当我点击

搜索我得到错误行:37对象预期,这是

的行< form name = ... ... onSubmit =" return validate(this);">代码

基本上只需输入名称,电子邮件和电话号码中输入的数据

并使用预制功能验证它们。现在我知道没有什么比c3common.js中的函数更糟糕了因为当我剪切并粘贴

它们进入脚本部分的html页面时,一切都开始工作
完美但是只要我将它们移动到另一个.js文件中并将

html页面与scr =c3common.js链接起来。一段代码我得到了错误。哦

,在你问文件是否在同一目录之前,这不是

问题。非常感谢你们的时间。


这里是:


test.html =


< html>

< head>

< title> ShowEmployees(使用JSTL)< / title>


< script src =" c3common.js" type =" text / javascript"

language =" JavaScript">


函数验证(表单)

{


window.alert(" CHECK!"); //这甚至都没有显示


var check = 1;


if(CheckName(form.name.value)== false)

{

window.alert(错误名称);

check = 0;

}

if(CheckEmail(form.email.value)== false)

{

window.alert(错误的电子邮件) ;

check = 0;

}

if(CheckPhoneNumber(form.telephone.value)== false)

{

window.alert(错误的电话);

check = 0;

}

返回支票;

}

< / script>

< / head>

< body>


< form name =" search"方法= QUOT; POST" onsubmit =" return

validate(this);">

< h1>搜索员工数据库< / h1>


< table>

< tr>

< td>名称< / td> < td>< input type =" text"命名= QUOT;名称"值= QUOT;" /> < / td>

< / tr>

< tr>

< td>电子邮件地址< / td> < td>< input type =" text" name =" email"

value ="" /> < / td>

< / tr>

< tr>

< td>电话号码< / td> < td>< input type =" text" name =" telephone"

value ="" /> < / td>

< / tr>

< tr>

< td>< input type =" hidden" ;名称= QUOT;动作" value =" showEmployees" />

< / td>

< td>< input type =" hidden"名称=&]页面"值= QUOT; 0" /> < / td>

< / tr>

< tr>

< td>< input type =" submit" ;命名= [提交"值= [搜寻" /> < / td>

< td>< input type =" reset" value ="重置所有字段" /> < / td>

< / tr>

< / table>

< / form>

< / body>

< / html>

解决方案



eruan ... @ hotmail.com写道:

< html>
< head>
< title> ShowEmployees(使用JSTL)< / title> ;

< script src =" c3common.js" type =" text / javascript"
language =" JavaScript">

函数验证(表单)




你不能使用一个< script> .js文件和内联代码的标记: -

内联代码在这种情况下被忽略。


更改为:


< script src =" c3common.js" type =" text / javascript">< / script>

< script type =" text / javascript">

//内联代码

< / script>


由于我在不同的地方反复看到这个错误,我认为

有些信誉良好 ;消息来源声称这是可能的。如果它是一个wiki我

会很高兴被指出所以我可以纠正这篇文章。


P.S.将表单字段命名为name通常是一个坏主意。 - 它可能会导致一些有趣的解决问题。

" customer"," user"," requestter"等等好多了。


哦,非常感谢你,出于某种原因,我之前尝试过这个但是

然后我已经对可能搞砸了的代码进行了一些更改,

现在完美地工作了。


VK写道:< blockquote class =post_quotes> eruan ... @ hotmail.com写道:

< html>
< head>
< title> ShowEmployees(使用JSTL) < / title>
< script src =" c3common.js" type =" text / javascript"
language =" JavaScript">

函数验证(表单)
您不能使用一个< script> .js文件和
内联代码的标记: -




你不能使用一个SCRIPT _tag_,因为HTML需要两个脚本

标签定义一个SCRIPT元素(打开和关闭标签不是

可选)。


但是你可以使用一个SCRIPT元素来导入文件和同时

定义该元素中的脚本。这样做并不是一个好主意,但它是一个合理普遍实施的设施。请参阅常见问题解答。
在这种情况下,
内联代码被忽略。


这取决于浏览器和当前

理解之外的因素。

更改为:

< script src =" c3common.js" type =" text / javascript">< / script>
< script type =" text / javascript">
//内联代码
< / script>


这是4 _tags_定义两个_elements_。在尝试就该主题提供

建议之前,获取对HTML的基本理解是一个好主意。 HTML标签和

元素之间的区别非常基本。

因为我在不同的地方反复看到这个错误,我认为有些 ;信誉"消息来源声称这是可能的。
< snip>


你看到一些你不理解的东西,并认为这是一个错误,

但是那个不是从另一个开始,特别是因为你没有实际理解你自己编写的代码(即使你不是自己必须意识到这一点)。

PS将表单字段命名为名称通常是一个坏主意。
- 它可能会导致一些有趣的寻址问题。
客户,用户,请求者等。更好。




名称或NAME也可以,因为javascript区分大小写。


Richard 。


Hi, I''ve been working on this for a while now and I can''t seem to find
out what is wrong with my code. I have 2 files one c3common.js which
only contains javascript functions for my main html page and my main
html page which is test.html. They are of course part of a much bigger
system of files but i have tracked down the problem to that reduced
part of the code. The page loads perfectly fine however when i click
search i get the error line:37 object expected, which is the line of
the <form name=...... onSubmit="return validate(this);"> The code
basically just takes the data entered in name, email and phone number
and validates them with premade functions. now i know theres nothing
wrong with the functions in c3common.js because when i cut and paste
them into the html page in the script part everything starts working
perfectly but as soon as i move them into another .js file and link the
html page with the scr="c3common.js" piece of code i get the error. Oh
and before you ask the files are in the same directory so thats not the
problem. Thanks a lot for your time guys.

here it goes:

test.html =

<html>
<head>
<title>ShowEmployees (using JSTL)</title>

<script src="c3common.js" type="text/javascript"
language="JavaScript">

function validate(form)
{

window.alert("CHECK!"); //this never even gets shown at all

var check =1;

if(CheckName(form.name.value) == false)
{
window.alert("wrong name");
check =0;
}
if(CheckEmail(form.email.value) == false)
{
window.alert("wrong email");
check =0;
}
if(CheckPhoneNumber(form.telephone.value) == false)
{
window.alert("wrong telephone");
check =0;
}

return check;
}
</script>
</head>

<body>

<form name="search" method="POST" onsubmit="return
validate(this);">
<h1>Searching Employees Database</h1>

<table>
<tr>
<td>Name</td> <td><input type="text" name="name" value=""/> </td>
</tr>
<tr>
<td>E-mail Address</td> <td><input type="text" name="email"
value=""/> </td>
</tr>
<tr>
<td>Phone number</td> <td><input type="text" name="telephone"
value=""/> </td>
</tr>
<tr>
<td><input type="hidden" name="action" value="showEmployees"/>
</td>
<td><input type="hidden" name="page" value="0" /> </td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Search"/> </td>
<td><input type="reset" value="Resets all fields"/> </td>
</tr>
</table>
</form>
</body>
</html>

解决方案


eruan...@hotmail.com wrote:

<html>
<head>
<title>ShowEmployees (using JSTL)</title>

<script src="c3common.js" type="text/javascript"
language="JavaScript">

function validate(form)



You cannot use one <script> tag for both .js file and inline code:-
inline code is being ignored in this case.

Change to:

<script src="c3common.js" type="text/javascript"></script>
<script type="text/javascript">
// inline code
</script>

As I see this error over and over in different places, I presume that
some "reputable" source claims that it''s possible. If it''s a wiki I
would appreciate to be pointed out so I could correct the article.

P.S. It is generally a bad idea to name you form field "name" - it may
lead to some funny addressing issues.
"customer", "user", "requester" etc. are much better.


ohh thank you soo much, for some reason i has tried that before but
then i had made some changes to the code that might have messed it up,
works perfectly now thx.


VK wrote:

eruan...@hotmail.com wrote:

<html>
<head>
<title>ShowEmployees (using JSTL)</title>

<script src="c3common.js" type="text/javascript"
language="JavaScript">

function validate(form)
You cannot use one <script> tag for both .js file and
inline code:-



You cannot use one SCRIPT _tag_ for anything as HTML requires two script
tags to define one SCRIPT element (opening and closing tags are not
optional).

But you can use one SCRIPT element to import a file and simultaneously
define script within that element. It isn''t a good idea to do so but it
is a reasonably commonly implemented facility; see the FAQ.
inline code is being ignored in this case.
That would depend upon the browser and factors beyond your current
understanding.
Change to:

<script src="c3common.js" type="text/javascript"></script>
<script type="text/javascript">
// inline code
</script>
That is 4 _tags_ defining two _elements_. Acquiring a basic
understanding of HTML would be a good idea prior to attempting to give
advice on the subject. The distinction between an HTML tag and an
element being pretty basic.
As I see this error over and over in different places, I
presume that some "reputable" source claims that it''s possible. <snip>

You see something you don''t understand and assume that it is an error,
but the one does not follow from the other, especially as you don''t
actually understand the code you write yourself (even if you are not
necessarily aware of that yourself).
P.S. It is generally a bad idea to name you form field "name"
- it may lead to some funny addressing issues.
"customer", "user", "requester" etc. are much better.



Name or NAME would do just as well, as javascript is case sensitive.

Richard.


这篇关于对象预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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