有人 - 请拜托,请**帮助:-( .js问题 [英] Someone - **please, please, please** help :-( .js problem

查看:59
本文介绍了有人 - 请拜托,请**帮助:-( .js问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个HTML页面,我试图导入2 .js文件(我创建)

into。这些文件是:row_functions.js和data_check_functions.js。

每当我把文件的内容带到这个HTML文件中时,所有都是

OK但是只要函数分开(就像现在一样),当我在页面上运行

时,我收到以下错误:


第73行,预期的对象。
<下面第73行是:


< INPUT onClick =" if(FTry2(PrepObj(''FrmX''))){

addRowToTable(''FDependents'',form.FDependSocialSecurityNumber.value,

form.FDependLastName.value,

form.FDependFirstName.value,form.FDependMiddleInitial。值,

form.FDependDateOfBirth.value,form.FDependState.value,

form.FDependZipCode.value,form.FDependPhoneNumber.value,

form.FDependAmountPaid.value,form.FDependRelationship.value); }"

type = button value ="添加 name =" Add">


换句话说,onClick

事件似乎有问题。它似乎没有认识到我在其他

..js文件中的功能。它没有进入FTry2。或者PrepObj或PrepObj。功能

(我在功能的入口处放置了一个警报,并且他们从未解雇过



有人请帮忙:-(我做错了什么?


----------------------- HTML PAGE以下列出------------------

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN" >

< HTML>

< HEAD>

< META http-equiv = Content-Type content =" text / html;

charset = windows-1252">

< / HEAD>

< script language =" javascript" TYPE = " application / x-javascript"

src =" file:/// C | Documents and Settings\Desktop\BASE

PAGE\row_functions.js" ;>

< script language =" javascript" TYPE =" application / x-javascript"

src =" file:/// C | Documents和设置\Desktop\BASE

PAGE \ data_check_functions.js" ;>


< SCRIPT language = JavaScript type =" text / javascript">

function PrepObj(Frm){

alert(搞定了这个狗屎);

//这样编写允许ShowFF显示()

with(document.forms [Frm])返回{Fawm:Frm,A:[

// {F:" Field"女:"什么" H:"如何" ?R:RegExp?V:ValFn?P {Params}},

{F:" FDependSocialSecurityNumber",W:" Social Security Number",H:" be

in ### - ## - #### format",V:RegCheckSocialOK},

{F:" FDependLastName",W:" Last Name",H: 非空白,V:FmlyOK},

{F:FDependFirstName,W:名字,H:非空白,V:FmlyOK},

{F:FDependMiddleInitial,W:Middle Initial,H:非空白,

V:FmlyOK},

{F:" FDependDateOfBirth",W:"出生"日期,H:"在有效的格式

MM-DD-YYYY",V:RegCheckDateOK,V:DateOK },

{F:" FDependState",W:" State",H:" non-blank",V:FmlyOK},

{F: FDependZipCode,W:Zip Code,H: ",V:RegCheckZipOK},

{F:" FDependPhoneNumber",W:" Phone Number",H:"在XXX-XXX-XXXX表格中

",V:RegCheckUSPhoneOK},

{F:" FDependAmountPaid",W:" Amount Paid",H:" ;美元和美分,

V:RegCheckUSDollarsOK},

{F:FDependRelationship,W:关系,H:非空白",

V:FmlyOK}

]}}


函数loadData(){

addRowToTable(1,2,3,4,5,6,7,8,9,10);

}

< / SCRIPT>

< BODY>

< FORM name = FrmX>

< div ID =" errmesg"> < / div>

社会安全号码< br>

& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;&  & nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 11 name = FDependSocialSecurityNumber>

< br>姓氏< br>

& nbsp;& nbsp;& nbsp;& nbsp;& & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 35 name = FDependLastName>

< br>名字< br>

& nbsp;& nbsp;& nbsp;& nbsp;& & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px"最大长度= 35名= FDependFirstName>

将峰; br> Middile初始<峰; br>

和NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 1 name = FDependMiddleInitial>

< br>出生日期< br>

& nbsp;& nbsp;& nbsp;& nbsp;&  & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px"最大长度= 12名= FDependDateOfBirth>

将峰; br>状态<峰; br>

和NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP ;& nbsp;& nbsp;& nbsp;< S ELECT size = 1"

style =" width:300px" name = FDependState>

< OPTION value = TX> TX< / OPTION>

< OPTION value = CA> CA< / OPTION>

< OPTION value = FL> FL< / OPTION>

< OPTION value = NY> NY< / OPTION>

< / SELECT>

< br>邮政编码< br>

& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp ;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 5 name = FDependZipCode>

< br>电话号码< br>

& nbsp;& nbsp;& nbsp;& nbsp;& & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 12 name = FDependPhoneNumber>

< br> Amount Paid< br>

& nbsp;& nbsp;& nbsp;& nbsp;& & nbsp;& nbsp;& nbsp;< I NPUT TYPE =" text"

style =" width:300px" maxLength = 8 name = FDependAmountPaid>

< br>关系< br>

& nbsp;& nbsp;& nbsp;& nbsp;& nbsp ;& nbsp;& nbsp;

< SELECT size = 1 style =" width:300px" name = FDependRelationship>

< OPTION value = 1 selected> 1- MOTHER< / OPTION>

< OPTION value = 2> 2- FATHER< / OPTION>

< OPTION value = 3> 3- SISTER< / OPTION>

< OPTION value = 4> 4-兄弟< / OPTION>

< OPTION value = 5> 5- GRANDMOTHER< / OPTION>

< OPTION value = 6> 6- GRANDFATHER< / OPTION>

< / SELECT>

< P>


< TABLE width = 388>< TBODY>< TR>

< TD width = 113>

< INPUT onClick =" if(FTry2(PrepObj(''FrmX''))){

addRowToTable(''FDependents'', form.FDependSocialSecurityNumber.value,

form.FDependLastName.value,

form.FDependFirstName.value,form.FDependMiddleInitial.value,

表格。 FDependDateOfBirth.value,form.FDependState.value,

form.FDependZipCode.value,form.FDependPhoneNumber.value,

form.FDependAmountPaid.value,form .FDependRelationship.value); }"

type = button value ="添加 name =" Add">

< / TD>

< TD width = 154>

< INPUT onclick = removeRowFromTable ( '' FDependents ''); type = button

value =删除名称=删除>

< / TD>< TD width = 154>

< INPUT onclick = openInNewWindow(this.form); type = submit value =继续

name =继续>

< / TD>

< / TR>

< / TBODY>< / TABLE>

< / FORM>

< / P>

< FORM name = FrmTabX action ="#">

< TABLE id =" FDependents" class = table cellSpacing = 0 cellPadding = 0

width =" 100%" align = left border = 1>

< TBODY>

< TR>

< TD vAlign = top bgColor = darkgreen>< ; FONT color =#006633>< FONT

color = #ffffff> Choice< / FONT> < / FONT>< / TD>

将TD VALIGN =顶部BGCOLOR =深绿>< FONT颜色=#FFFFFF>社会秒

号< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT

color = #ffffff> LastName< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff> First

名称< / FONT>< / TD>

将TD VALIGN =顶部BGCOLOR =深绿>< FONT颜色=#FFFFFF>中间

将/ FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff>日期

出生< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff>状态< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff> ;邮编

代码< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff>电话
Number< / FONT>< / TD>

& lt; TD vAlign = top bgColor = darkgreen>< FONT color = #ffffff>金额Pd。

< / FONT>< / TD>

< TD vAlign = top bgColor = darkgreen>< FONT

color = #ffffff> Relationship< / FONT>< / TD>< / TR>

< TR>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> * < / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< TD vAlign = top> *< / TD>

< / TR>

< / TBODY>< / TABLE>< / P>

< / FORM>

< / BODY>

< / HTML>

解决方案

milkyway写道:你好,

我有一个HTML页面,我试图导入2 .js文件(我创建)
。这些文件是:row_functions.js和data_check_functions.js。
每当我把文件的内容带到这个HTML文件中时,一切都好了,但每当函数被分开时(就像现在一样),当我运行页面,我收到以下错误:

第73行,预期对象。

以下第73行是:

< INPUT onClick =" if(FTry2(PrepObj(''FrmX''))){
addRowToTable(''FDependents'',form.FDependSocialSecurityNumber.value,




在哪里定义了''addRowToTable'?


将你的问题减少到最小的代码仍然显示它

(比如说)一个表单输入和最小的HTML)并重新发布 - 至少摆脱

所有& nbsp; - 使用填充或边距或其他一些布局技术。


尝试更改参考文献,例如:


form.FDependSocialSecurityNumber.value


to:


forms.FrmX.FDependSocialSecurityN umber.value


此外,您的所有属性值都应该被引用,而不仅仅是引用它们的某些属性值。并且沟渠language =''javascript''" - 它已被折旧且

由type =" text / javascript"取代。


-

Fred


2005年1月16日05:01:36 -0800,在comp.lang.javascript" milkyway"

< d0 *** ***@hotmail.com>写道:

|您好,
|
|我有一个HTML页面,我试图导入2 .js文件(我创建)
|成。这些文件是:row_functions.js和data_check_functions.js。
|每当我将文件的内容带入这个HTML文件时,都是
|好的,但只要功能分开(就像现在一样),当我运行
|时该页面,我收到以下错误:
|
|第73行,预期对象。
|
|下面的第73行是:
|
| < INPUT onClick =" if(FTry2(PrepObj(''FrmX''))){
| addRowToTable(''FDependents'',form.FDependSocialSecurityNumber.value,
| form.FDependLastName.value,
| form.FDependFirstName.value,form.FDependMiddleInitial.value,
| form.FDependDateOfBirth .value,form.FDependState.value,
| form.FDependZipCode.value,form.FDependPhoneNumber.value,
| form.FDependAmountPaid.value,form.FDependRelationship.value); }"
| type = button value ="添加 name =" Add">
|
|换句话说,onClick似乎有问题。
|事件。它似乎没有认识到我在其他的功能
| .js文件。它没有进入FTry2。或者PrepObj或PrepObj。功能
| (我在功能的入口处放置了一个警报,并且
|他们从未解雇过。
|
|有人请帮助:-(我做错了什么?
|
| -----------------------下面列出的HTML页面-------------- ----
|<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">
|< HTML>
|< HEAD> ;
|< META http-equiv = Content-Type content =" text / html;
| charset = windows-1252">
|< / HEAD>
|< script language =" javascript" TYPE =" application / x-javascript"
| src =" file:/// C | Documents and Settings \Desktop\BASE
| PAGE\row_functions.js">
|< script language =" javascript" TYPE =" application / x-javascript"
| src =" file:/// C |文档和设置\Desktop\BASE
| PAGE \ datata_check_functions.js">




您的脚本文件指向您的har你应该把

链接指向你网站上的文件夹。例如,脚本

文件位于名为scripts的文件夹中,您的< script>标签看起来像

喜欢:

< script language =" javascript" TYPE =" application / x-javascript"

src =" folder / row_functions.js" >

< script language =" javascript" TYPE =" application / x-javascript"

src =" folder / data_check_functions.js" >


脚本标签等通常应放在< head>< / head>

标签之间,浏览器可能会忽略它们代码。


Type属性应为type =" text / javascript"但不要引用我

就可以了。


-------------------- -------------------------------------------
jn **** @ yourpantsbigpond.net.au :脱掉裤子回复

---- -------------------------------------------------- ---------


Fred Oz写道:

< snip>

尝试更改引用如:

form.FDependSocialSecurityNumber.value

:form.FrmX.FDependSocialSecurityNumber.value


这些属性访问器中的第一个(最左边)项是(在ECMAScript

生产规则条款中)一个标识符,将根据

范围链解析(内部生成的,用于在

内部事件属性字符串中定义的代码)事件处理函数(根据ECMA

272(第3版)第10.1.4节范围链和识别r $ / $
分辨率。


因此,任何一个属性访问器的无错分辨率

要求最左边的标识符对应于函数的作用域链上的一个对象的命名属性

,该对象包含对象的

引用。当没有使用闭包时,执行javascript函数的正常范围链将包含

激活/变量对象(保持对函数的正式

参数,命名为内部函数声明和局部变量)

单个执行上下文后跟全局/窗口对象。

全局/窗口通常不会期望对象具有名为form的

属性。或形式或形式所以这两个属性

访问器都会失败。


在实践中,一些浏览器(包括更常见的浏览器)添加一个自定义

范围链到它们内部的事件处理函数

从内部事件属性字符串定义的代码生成。那些

自定义范围链确实包含来自DOM的一些对象,取决于所讨论的浏览器,
。如果浏览器已将指定属性的INPUT

元素添加到范围链中,则

" form"将解析作为对指定的W3C HTML DOM的引用(和

看似普遍支持) - 表单 - INPUT元素的属性

(或者更准确地说是HTMLInputElement接口) 。当 -

文档 - 元素被添加到范围链形式时将被解析

作为指定的W3C HTML DOM - 表单 - HTMLDocument

接口的集合(通常在HTML DOM中实现,但缺少一些形式

旧的XHTML DOM实现)。


实验表明,所有为内部生成的事件处理函数提供

自定义范围链的浏览器<来自内部事件属性字符串的
将该属性出现在该范围链上的元素

。但是,在该范围链上放置一个

引用 - 文档 - 通常不会实现
。因此,建议从原来的属性转换为建议的替代方案将会牺牲一些跨浏览器

的兼容性,这是没有特别好的理由。


另一方面,内部

生成的事件处理函数的自定义范围链的创建未在任何已发布的规范中定义(或甚至建议

by) /推荐,所以令人惊讶的是

创建它们的行为不同。并且它也不是令人惊讶的是,有些(合理的标准兼容)浏览器

根本没有实现这样的机制(留下它们的内部

生成事件处理函数,其范围链满足ECMA

262但不再进一步)。对于这些浏览器,属性访问器

公式将出错,而不是解析为有用的值。


为了最大化跨浏览器兼容性,

应编写代码的内部事件属性的字符串值

,好像它是任何顶级函数体定义

ECMAScirpt / javascript函数分配给

a DOM元素的事件处理属性。不依赖于不定期实施的自定义范围

链。相反,属性访问器应该能够在正常的ECMAScirpt执行环境中成功解析。

因此: -


形式。 FrmX.FDependSocialSecurityNumber.value


- 最好指定为: -


document.forms.FrmX.FDependSocialSecurityNumber.va lue

- (因为 - 文档 - 可以预期是

全局/窗口对象的属性,因此将在任何和所有的范围链上/>
ECMAScript函数)。并且: -


form.FDependSocialSecurityNumber.value


- 会更好: -


this.form.FDependSocialSecurityNumber.value


- 因为 - this - 关键字是指用作方法执行

函数的对象(在与该元素关联的

事件处理程序的情况下的INPUT元素。


后一个属性访问器可能是最好的选项,因为它允许

通过表格引用而不对

表格的名称/ ID感兴趣。允许对表单进行匿名处理,使代码更加便携。


理想情况下,两个属性访问者都会引用单个表单

控件通过表单' - - elements - 集合完全

符合W3C DOM规范,而不是依赖

''快捷方式''将这些控件称为

表单元素本身的命名属性(即使没有可识别

形式的可编写脚本的浏览器,也不会实现''快捷方式'' )。

此外,所有属性值都应该引用,而不仅仅是其中一些。



< snip>


在HTML中(与XHTML相对)''应该''是一个过于强大的术语。引用所有

属性字符串通常被认为是一种良好的做法,但规则存在

,它们定义何时必须引用属性字符串,何时不引用

必要的。引用所有属性字符串的好处是,它可以永远不会出错,并且不必记住关于何时必须完成

的规则。


后续设置为comp.lang.javascript。


Richard。


Hello,

I have an HTML page that I am trying to import 2 .js file (I created)
into. These files are: row_functions.js and data_check_functions.js.
Whenever I bring the contents of the files into this HTML file, all is
OK but whenever the functions are separated (as it is now), when I run
the page, I get the following error:

Line 73, object expected.

Line 73 below is:

<INPUT onClick="if (FTry2(PrepObj(''FrmX''))) {
addRowToTable(''FDependents'', form.FDependSocialSecurityNumber.value,
form.FDependLastName.value,
form.FDependFirstName.value, form.FDependMiddleInitial.value,
form.FDependDateOfBirth.value, form.FDependState.value,
form.FDependZipCode.value, form.FDependPhoneNumber.value,
form.FDependAmountPaid.value, form.FDependRelationship.value); } "
type=button value=" Add " name="Add">

In other words, there seems to be something wrong with the "onClick"
event. It does not seem to recognize the functions I have in the other
..js files. It does not get into the "FTry2" or the "PrepObj" functions
(I had placed an "alert" there at the entry point of the functions and
they never fired.

Someone please help :-( What am I doing wrong?

----------------------- HTML PAGE LISTED BELOW ------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
</HEAD>
<script language="javascript" TYPE="application/x-javascript"
src="file:///C|Documents and Settings\Desktop\BASE
PAGE\row_functions.js" >
<script language="javascript" TYPE="application/x-javascript"
src="file:///C|Documents and Settings\Desktop\BASE
PAGE\data_check_functions.js" >

<SCRIPT language=JavaScript type="text/javascript">
function PrepObj(Frm) {
alert("got in this shit");
// So written to allow display by ShowFF()
with (document.forms[Frm]) return { Fawm:Frm, A:[
// {F:"Field" W:"What" H:"How" ?R:RegExp ?V:ValFn ?P{Params}},
{F:"FDependSocialSecurityNumber", W:"Social Security Number", H:"be
in ###-##-#### format ", V:RegCheckSocialOK},
{F:"FDependLastName", W:"Last Name", H:"non-blank", V:FmlyOK},
{F:"FDependFirstName", W:"First Name", H:"non-blank", V:FmlyOK},
{F:"FDependMiddleInitial", W:"Middle Initial", H:"non-blank",
V:FmlyOK},
{F:"FDependDateOfBirth", W:"Date of Birth", H:"in valid format
MM-DD-YYYY", V:RegCheckDateOK, V:DateOK},
{F:"FDependState", W:"State", H:"non-blank", V:FmlyOK},
{F:"FDependZipCode", W:"Zip Code", H:" ", V:RegCheckZipOK},
{F:"FDependPhoneNumber", W:"Phone Number", H:" in XXX-XXX-XXXX form
", V:RegCheckUSPhoneOK},
{F:"FDependAmountPaid", W:"Amount Paid", H:"in dollars and cents ",
V:RegCheckUSDollarsOK},
{F:"FDependRelationship", W:"Relationship", H:"non-blank",
V:FmlyOK}
] } }

function loadData(){
addRowToTable(1,2,3,4,5,6,7,8,9,10);
}
</SCRIPT>
<BODY>
<FORM name=FrmX >
<div ID="errmesg"> </div>
Social Security Number <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=11 name=FDependSocialSecurityNumber>
<br>Last Name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=35 name=FDependLastName>
<br>First Name<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=35 name=FDependFirstName>
<br>Middile Initial<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=1 name=FDependMiddleInitial>
<br>Date Of Birth<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=12 name=FDependDateOfBirth>
<br>State<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<S ELECT size=1 "
style="width:300px" name=FDependState>
<OPTION value=TX >TX</OPTION>
<OPTION value=CA>CA</OPTION>
<OPTION value=FL>FL</OPTION>
<OPTION value=NY>NY</OPTION>
</SELECT>
<br>Zip Code<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=5 name=FDependZipCode>
<br>Phone Number<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=12 name=FDependPhoneNumber>
<br>Amount Paid<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<I NPUT TYPE ="text"
style="width:300px" maxLength=8 name=FDependAmountPaid>
<br>Relationship<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<SELECT size=1 style="width:300px" name=FDependRelationship>
<OPTION value=1 selected>1- MOTHER</OPTION>
<OPTION value=2>2- FATHER</OPTION>
<OPTION value=3>3- SISTER</OPTION>
<OPTION value=4>4- BROTHER</OPTION>
<OPTION value=5>5- GRANDMOTHER</OPTION>
<OPTION value=6>6- GRANDFATHER</OPTION>
</SELECT>
<P>

<TABLE width=388><TBODY><TR>
<TD width=113>
<INPUT onClick="if (FTry2(PrepObj(''FrmX''))) {
addRowToTable(''FDependents'', form.FDependSocialSecurityNumber.value,
form.FDependLastName.value,
form.FDependFirstName.value, form.FDependMiddleInitial.value,
form.FDependDateOfBirth.value, form.FDependState.value,
form.FDependZipCode.value, form.FDependPhoneNumber.value,
form.FDependAmountPaid.value, form.FDependRelationship.value); } "
type=button value=" Add " name="Add">
</TD>
<TD width=154>
<INPUT onclick=removeRowFromTable(''FDependents''); type=button
value=Remove name=Remove>
</TD><TD width=154>
<INPUT onclick=openInNewWindow(this.form); type=submit value=Continue
name=Continue>
</TD>
</TR>
</TBODY></TABLE>
</FORM>
</P>
<FORM name=FrmTabX action="#">
<TABLE id="FDependents" class=table cellSpacing=0 cellPadding=0
width="100%" align=left border=1>
<TBODY>
<TR>
<TD vAlign=top bgColor=darkgreen><FONT color=#006633><FONT
color=#ffffff>Choice</FONT> </FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Social Sec
No.</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT
color=#ffffff>LastName</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>First
Name</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Middle
</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Date of
Birth</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>State </FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Zip
Code</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Phone
Number</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT color=#ffffff>Amount Pd.
</FONT></TD>
<TD vAlign=top bgColor=darkgreen><FONT
color=#ffffff>Relationship</FONT></TD></TR>
<TR>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
<TD vAlign=top>*</TD>
</TR>
</TBODY></TABLE></P>
</FORM>
</BODY>
</HTML>

解决方案

milkyway wrote:

Hello,

I have an HTML page that I am trying to import 2 .js file (I created)
into. These files are: row_functions.js and data_check_functions.js.
Whenever I bring the contents of the files into this HTML file, all is
OK but whenever the functions are separated (as it is now), when I run
the page, I get the following error:

Line 73, object expected.

Line 73 below is:

<INPUT onClick="if (FTry2(PrepObj(''FrmX''))) {
addRowToTable(''FDependents'', form.FDependSocialSecurityNumber.value,



where is ''addRowToTable'' defined?

Reduce your problem to the smallest amount of code to still show it
(say one form input and minimal HTML) and re-post - at least get rid of
all the &nbsp; - use padding or margin or some other layout technique.

Try changing references such as:

form.FDependSocialSecurityNumber.value

to:

forms.FrmX.FDependSocialSecurityNumber.value

Also, all your attribute values should be quoted, not just some of
them. And ditch "language=''javascript'' " - it''s depreciated and
replaced by type="text/javascript".

--
Fred


On 16 Jan 2005 05:01:36 -0800, in comp.lang.javascript "milkyway"
<d0******@hotmail.com> wrote:

| Hello,
|
| I have an HTML page that I am trying to import 2 .js file (I created)
| into. These files are: row_functions.js and data_check_functions.js.
| Whenever I bring the contents of the files into this HTML file, all is
| OK but whenever the functions are separated (as it is now), when I run
| the page, I get the following error:
|
| Line 73, object expected.
|
| Line 73 below is:
|
| <INPUT onClick="if (FTry2(PrepObj(''FrmX''))) {
| addRowToTable(''FDependents'', form.FDependSocialSecurityNumber.value,
| form.FDependLastName.value,
| form.FDependFirstName.value, form.FDependMiddleInitial.value,
| form.FDependDateOfBirth.value, form.FDependState.value,
| form.FDependZipCode.value, form.FDependPhoneNumber.value,
| form.FDependAmountPaid.value, form.FDependRelationship.value); } "
| type=button value=" Add " name="Add">
|
| In other words, there seems to be something wrong with the "onClick"
| event. It does not seem to recognize the functions I have in the other
| .js files. It does not get into the "FTry2" or the "PrepObj" functions
| (I had placed an "alert" there at the entry point of the functions and
| they never fired.
|
| Someone please help :-( What am I doing wrong?
|
| ----------------------- HTML PAGE LISTED BELOW ------------------
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
| <HTML>
| <HEAD>
| <META http-equiv=Content-Type content="text/html;
| charset=windows-1252">
| </HEAD>
| <script language="javascript" TYPE="application/x-javascript"
| src="file:///C|Documents and Settings\Desktop\BASE
| PAGE\row_functions.js" >
| <script language="javascript" TYPE="application/x-javascript"
| src="file:///C|Documents and Settings\Desktop\BASE
| PAGE\data_check_functions.js" >



Your script files are pointing to your hard drive. You should make the
links point to the folder within your website. For example the script
files are in a folder called scripts, your <script> tags would look
like:
<script language="javascript" TYPE="application/x-javascript"
src="folder/row_functions.js" >
<script language="javascript" TYPE="application/x-javascript"
src="folder/data_check_functions.js" >

Script tags etc should normally be placed between the <head></head>
tags, the browser could be ignoring them in your code.

The Type attribute should be type="text/javascript" but don''t quote me
on that.

---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------


Fred Oz wrote:
<snip>

Try changing references such as:

form.FDependSocialSecurityNumber.value

to:

forms.FrmX.FDependSocialSecurityNumber.value
The first (left most) item in these property accessors is (in ECMAScript
production rule terms) an Identifier and will be resolved against the
scope chain of the (internally generated, for code defined in an
intrinsic event attribute strings) event handling function (as per ECMA
272 (3rd edition) Section 10.1.4 "Scope Chain and Identifier
Resolution").

As a result, error-free resolution of either of those property accessors
requires that the left most Identifier correspond with a named property
of one of the objects on the function''s scope chain that holds a
reference to an object. When closures are not being employed, the normal
scope chain of an executing javascript function will contain the
Activation/Variable object (holding references to the function''s formal
parameters, named inner function declarations and local variables) of
the individual execution context followed by the global/window object.
The global/window object would not normally be expected to have
properties named "form" or "forms" and so both of those property
accessors will fail.

In practice some browsers (including the more common ones) add a custom
scope chain to the event handling functions that they internally
generate from intrinsic event attribute string defined code. Those
custom scope chains do include a number of objects from the DOM,
depending on the browser in question. If the browser has added the INPUT
element on which the attribute is specified to the scope chain, then
"form" will resolve as a reference to the W3C HTML DOM specified (and
seemingly universally supported) - form - property of the INPUT element
(or, more precisely the HTMLInputElement interface). And when the -
document - element is added to the scope chain "forms" will be resolved
as the W3C HTML DOM specified - forms - collection of the HTMLDocument
interface (universally implemented in HTML DOMs, but missing form some
older XHTML DOM implementations).

Experimentation has suggested that all of the browsers that do provide a
custom scope chain for event handling functions internally generated
from intrinsic event attribute strings will place the element on which
the attribute appears on that scope chain. However, the placing of a
reference to the - document - on that scope chain is less commonly
implemented. Thus the proposed switch from the original property
accessor to the proposed alternative will sacrifice some cross-browser
compatibility for no particularly good reason.

On the other hand, the creating of custom scope chains for internally
generated event handling functions is not defined in (or even suggested
by) any published specification/recommendation, so it is surprising that
where they are created they differ in behaviour. And it is also not
surprising that some (otherwise reasonably standards compliant) browsers
do not implement such a mechanism at all (leaving their internally
generated event handling functions with scope chains that satisfy ECMA
262 but go no further). For these browsers both property accessor
formulations will error, rather than resolving to useful values.

To maximise the cross-browser compatibility the code defined in the
string values of intrinsic event attributes that code should be written
as if it was the function body definition of any top level
ECMAScirpt/javascript function assigned to an event handling property of
a DOM element. No reliance on the inconstantly implemented custom scope
chains should be made. Instead property accessors should be capable of
being sucessfully resolved in a normal ECMAScirpt execution context.
Thus:-

forms.FrmX.FDependSocialSecurityNumber.value

- would be better specified as:-

document.forms.FrmX.FDependSocialSecurityNumber.va lue

-(because - document - can be expected to be a property of the
global/window object and so will be on the scope chain of any and all
ECMAScript functions). And:-

form.FDependSocialSecurityNumber.value

- would be better as:-

this.form.FDependSocialSecurityNumber.value

- because the - this - keyword refers to the object with which the
function is executed as a method (the INPUT element in the case of an
event handler associated with that element).

The latter property accessor probably being the best option as it allows
referencing via the form without any interest in the name/ID of the
form. Allowing the form to be treated anonymously and so making the code
more portable.

Ideally both property accessors would reference the individual form
controls via the form''s - elements - collection in order to fully
conform with the W3C DOM specification, rather than relying on the
''shortcut'' of referring to those controls as named properties of the
form element itself (even though no scriptable browsers that understand
forms are known that do not implement the ''shortcut'').
Also, all your attribute values should be quoted, not
just some of them.


<snip>

In HTML (as opposed to XHTML) ''should'' is too strong a term. Quoting all
attribute strings is often suggested as good practice but rules exist
that define when attribute strings must be quoted, and when it is not
necessary. The advantage of quoting all attribute strings is that it can
never be wrong and makes it unnecessary to remember the rules about when
it must be done.

Follow-ups set to comp.lang.javascript.

Richard.


这篇关于有人 - 请拜托,请**帮助:-( .js问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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