引用小部件 - document.formname vs this.form [英] Referencing widgets - document.formname vs this.form

查看:56
本文介绍了引用小部件 - document.formname vs this.form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我验证小部件的方法中,我编写了javascript函数。

在文档的最后,在表单内部,我调用了函数


< FORM NAME =" testit">

< INPUT TYPE =" TEXT" VALUE =" 2英寸NAME =" _widge1">

< INPUT TYPE =" BUTTON&qu​​ot; VALUE ="编辑" onclick =" valfunc(this.form);">

< / FORM>


其中


函数valfunc(f){

if(f._widge1.value == 2){alert(" A 2!");}

}


有时,奇怪的是,javascript无法找到_widge1。在这种情况下,我必须重写函数


函数valfunc(f){

if(document.testit。 _widge1.value == 2){alert(" A 2!");}

}


这显然不那么普遍,因为它只适用于一组

的表格,名称为testit的那些。


为什么会出现这个问题?是否有一些关于何时我可以将

沿着该表格传递为this.form?

In my approach to validation for widgets, i write javascript functions.
At the end of the document, inside the form, i invoke the function as

<FORM NAME="testit">
<INPUT TYPE="TEXT" VALUE="2" NAME="_widge1">
<INPUT TYPE="BUTTON" VALUE="Edit" onclick="valfunc(this.form);">
</FORM>

where

function valfunc(f) {
if (f._widge1.value == 2) {alert("A 2!");}
}

Sometimes, oddly, the javascript cannot find _widge1. In such cases, I
must rewrite the function as

function valfunc(f) {
if (document.testit._widge1.value == 2) {alert("A 2!");}
}

This is clearly a little less general, as it only applies to one group
of forms, those with the name testit.

Why does this problem occur? Is there some rule about when I can pass
along that form as "this.form"?

推荐答案

Data Guy写道:
Data Guy wrote:
在我验证小部件的方法中,我编写了javascript函数。
在文档的最后,在表单内部,我调用函数为

< FORM NAME =" testit">
< INPUT TYPE =" TEXT" VALUE =" 2英寸NAME =" _widge1">
< INPUT TYPE =" BUTTON&qu​​ot; VALUE ="编辑" onclick =" valfunc(this.form);">
< / FORM>

其中

函数valfunc(f){
if(f._widge1.value == 2){alert(" A 2!");}
}
有时,奇怪的是,javascript无法找到_widge1。在这种情况下,我必须将函数重写为

函数valfunc(f){
if(document.testit._widge1.value == 2){alert(") A 2!);}
}
这显然有点不太通用,因为它只适用于一组形式,名称为testit的形式。


尝试使用元素集合而不是点符号:


if(f.elements [''_ widge1'']。value = = 2){.....}

为什么会出现这个问题?


除非_导致问题,否则不应该这样。

是否有一些关于何时可以将
传递给该表格的规则this.form?
In my approach to validation for widgets, i write javascript functions.
At the end of the document, inside the form, i invoke the function as

<FORM NAME="testit">
<INPUT TYPE="TEXT" VALUE="2" NAME="_widge1">
<INPUT TYPE="BUTTON" VALUE="Edit" onclick="valfunc(this.form);">
</FORM>

where

function valfunc(f) {
if (f._widge1.value == 2) {alert("A 2!");}
}

Sometimes, oddly, the javascript cannot find _widge1. In such cases, I
must rewrite the function as

function valfunc(f) {
if (document.testit._widge1.value == 2) {alert("A 2!");}
}

This is clearly a little less general, as it only applies to one group
of forms, those with the name testit.
Try using the elements collection instead of the dot notation:

if (f.elements[''_widge1''].value == 2){.....}
Why does this problem occur?
It shouldn''t unless the _ is causing a problem.
Is there some rule about when I can pass
along that form as "this.form"?




我可能错了,但我相信它与元素名称的关系比

this.form更多。但是什么浏览器显示这种行为?

-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组周刊



I could be wrong but I believe its related more to the element name than
the this.form. But what browser is displaying that behavior?
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


Data Guy说:
Data Guy said:

在我的小部件验证方法中,我编写了javascript函数。
在文档的最后,在表单内部,我调用函数

< FORM NAME =" testit">
< INPUT TYPE =" TEXT" VALUE =" 2英寸NAME =" _widge1">
< INPUT TYPE =" BUTTON&qu​​ot; VALUE ="编辑" onclick =" valfunc(this.form);">
< / FORM>

其中

函数valfunc(f){
if(f._widge1.value == 2){alert(" A 2!");}
}
有时,奇怪的是,javascript无法找到_widge1。在这种情况下,我必须将函数重写为

函数valfunc(f){
if(document.testit._widge1.value == 2){alert(") A 2!;}
}
这显然有点不太通用,因为它只适用于一组形式,名称为testit的形式。

为什么会出现这个问题?是否有一些关于何时可以将
沿着该表格传递为this.form的规则?

In my approach to validation for widgets, i write javascript functions.
At the end of the document, inside the form, i invoke the function as

<FORM NAME="testit">
<INPUT TYPE="TEXT" VALUE="2" NAME="_widge1">
<INPUT TYPE="BUTTON" VALUE="Edit" onclick="valfunc(this.form);">
</FORM>

where

function valfunc(f) {
if (f._widge1.value == 2) {alert("A 2!");}
}

Sometimes, oddly, the javascript cannot find _widge1. In such cases, I
must rewrite the function as

function valfunc(f) {
if (document.testit._widge1.value == 2) {alert("A 2!");}
}

This is clearly a little less general, as it only applies to one group
of forms, those with the name testit.

Why does this problem occur? Is there some rule about when I can pass
along that form as "this.form"?




您需要学习新的术语。


他们不是小部件,他们是控件或表单控件。

他们不是具有相同名称的表单,而是

相同的表单(名为testit。

表单控件总是有一个名为form的属性,

将始终引用它拥有的所有控件。


所以,如果你不能访问this.form.somename,那么某个名字

不是以相同的形式控制。


发布一个案例的小例子,你不能以这种方式访问​​

控件,有人可能会能够发现

为什么。



You need to learn new terminology.

They''re not widgets, they''re controls, or form controls.
They''re not forms with the same name, they are controls of
the same form (which is named "testit".
Form controls always have an attribute named "form", which
will always have references to all of the controls it owns.

So, if you can''t access this.form.somename, then somename
is not a control in the same form.

Post a small example of a case in which you can''t access a
control this way, and somebody will probably be able to spot
why.


Randy Webb< Hi ************ @ aol.com>写道:

Randy Webb <Hi************@aol.com> writes:

if(doc ument.testit._widge1.value == 2){alert(" A 2!");}
....
if (document.testit._widge1.value == 2) {alert("A 2!");} ....
尝试使用元素集合而不是点符号:

if(f.elements [''_ widge1'']。value == 2){.....}
Try using the elements collection instead of the dot notation:

if (f.elements[''_widge1''].value == 2){.....}




不应该改变一件事。 " _widge1"是一个非常好的标识符。

为什么会出现这个问题?



Shouldn''t change a thing. "_widge1" is a perfectly good identifier.
Why does this problem occur?



除非_导致问题。



It shouldn''t unless the _ is causing a problem.




一个cuncur,和_不应该造成问题。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM。 html>

''没有判断的信仰只会降低精神神圣。''



A cuncur, and the "_" shouldn''t be causing a problem.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


这篇关于引用小部件 - document.formname vs this.form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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