document.forms [表格名称] .elemName [英] document.forms[formName].elemName

查看:78
本文介绍了document.forms [表格名称] .elemName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< form name =" myForm" action =" ...">

< p>< input type =" text"名称= QUOT; myElem">< / p为H.

将/形式>


据我是能够得到下面是

访问HTML表单元素的标准方法:


document.forms [''myForm'']。elements [''myElem'']


但我也看到了以下内容:


document.forms [''myForm'']。myElem


以后是正确的使用方法,或者只是在我尝试使用的所有浏览器(Windows 6上的IE 6,Mozilla 1.8,Opera 9.2和Safari 3.1)

支持它与现有Web内容的兼容性吗?


-

Stanimir

解决方案

Stanimir Stamenkov写道:


< form name =" myForm" action =" ...">

< p>< input type =" text"名称= QUOT; myElem">< / p为H.



'div''元素而不是'p''在这里是语义。它不是一个

文本段落,是吗?


< / form>


据我所知,以下是访问HTML表单元素的标准方式:


document.forms ['' myForm'']。elements [''myElem'']



正确,就标准而言。

` document''所引用的对象实现了W3C DOM Level 2 HTML的HTMLDocument接口

在许多情况下是一个专有但合理的设计决策。

而我还发现以下内容:


document.forms [ '' myForm的 ''] myElem


以后是否正确使用



我认为它现在符合弃用用途。

http://docs.sun.com/source/816- 6408-10 / form.htm


或者只是发生所有浏览器我已经尝试过(IE 6)
,Mozilla 1.8,Opera 9.2和Windows 3.1上的Safari 3.1

支持它与现有Web内容的兼容性?



似乎是这样。

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-40002357
http: //www.w3.org/TR/DOM-Level-2-HTML/glossary.html

PointedEars

-

Prototype.js是由那些不懂javascript的人写的

谁不懂javascript。不知道javascript的人不是设计使用javascript的系统的最佳建议来源。

- Richard Cornford,cljs,< f8 ** *****************@news.demon.co.uk>


5月25日下午3:12, Stanimir Stamenkov< s7a ... @ netscape.netwrote:


< form name =" myForm" action =" ...">

< p>< input type =" text"名称= QUOT; myElem">< / p为H.

将/形式>


据我是能够得到下面是

访问HTML表单元素的标准方法:


document.forms [''myForm'']。elements [''myElem'']


但我也看到了以下内容:


document.forms [''myForm'']。myElem



后者是同一元素的快捷方式访问器。大多数

时间的快捷方式可以用来保存你的键盘和你的b $ b指尖提示:-)当表格控件名称没有时,情况并非如此t $ / $
符合Javascript有效标识符规则。想象一下,你有一套

的放射性物品,其名称已根据PHP服务器端预处理进行调整,

所以类似于< input type =" radio" name =" radio [0]">," radio [1]"

document.forms [' 'myForm'']。radio [0]你会得到运行时错误。在

的同时,完全限定的符号将起作用:

document.forms [''myForm'']。elements [''radio [0]'']


VK写道:

在5月25日下午3点12,斯坦尼米尔Stamenkov< S7A ... @ netscape.netwrote:


>< form name =" myForm"行动= QUOT; ..."< p为H.;<输入类型= QUOT;文本"
名称= QUOT; myElem">< / P< /形式>

至于我能够得到以下内容是访问HTML表单元素的标准方法:

document.forms [''myForm'']。elements [''myElem'' ]

但我也看到了以下内容:

document.forms [''myForm'']。myElem



后者是同一元素的快捷方式访问器。



它是对同一元素_object_的引用,如果是这样的话。


大部分时间都是快捷方式表单可以用来保存你的键盘

和你的指尖:-)当表单控件名称

不符合Javascript有效标识符时不是这种情况规则。



错误。专有的引用允许


document.forms [''myForm''] [" myElem []"]





使用符合标准的方法而不是专有的b / b
的原因是后者是*专有的*。应该避免使用专有方法

,并且应该只作为符合b b b标准的方法的后备,因为从理论上讲,根据定义它们可以b / b
打破代码暴露给另一个,以前不为人知的,b / b
用户代理。

PointedEars

-

任何打击此页面的人最好用浏览器X查看标签

a网页似乎渴望过去的糟糕时光,在网络之前,

当你几乎没有机会阅读另一台计算机,另一台文字处理器或其他网络上的文件。 - Tim Berners-Lee


<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>
</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms[''myForm''].elements[''myElem'']

But I have also seen the following:

document.forms[''myForm''].myElem

Is the later correct usage or it just happens all browsers I''ve
tried with (IE 6, Mozilla 1.8, Opera 9.2 and Safari 3.1 on Windows)
support it for compatibility with existing Web content?

--
Stanimir

解决方案

Stanimir Stamenkov wrote:

<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>

A `div'' element instead of `p'' would be semantic here. It isn''t exactly a
text paragraph, is it?

</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms[''myForm''].elements[''myElem'']

Correct, as far as the standard goes. That the object referred to by
`document'' implements the HTMLDocument interface of W3C DOM Level 2 HTML
in many cases has been a proprietary, yet reasonable design decision.

But I have also seen the following:

document.forms[''myForm''].myElem

Is the later correct usage

I think it qualifies as deprecated usage by now.

http://docs.sun.com/source/816-6408-10/form.htm

or it just happens all browsers I''ve
tried with (IE 6, Mozilla 1.8, Opera 9.2 and Safari 3.1 on Windows)
support it for compatibility with existing Web content?

It would seem so.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-40002357
http://www.w3.org/TR/DOM-Level-2-HTML/glossary.html
PointedEars
--
Prototype.js was written by people who don''t know javascript for people
who don''t know javascript. People who don''t know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>


On May 25, 3:12 pm, Stanimir Stamenkov <s7a...@netscape.netwrote:

<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>
</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms[''myForm''].elements[''myElem'']

But I have also seen the following:

document.forms[''myForm''].myElem

The latter is a shortcut accessor to the same element. Most of the
time the shortcut form can be used to preserve your keyboard and your
finger tips :-) It is not the case when the form control name doesn''t
conform with Javascript valid identifier rules. Imagine you have a set
of radioboxes with names adjusted for PHP server-side pre-processing,
so something like <input type="radio" name="radio[0]">, "radio[1]"
etc. Obviously by using the shortcut form
document.forms[''myForm''].radio[0] you''ll get runtime errors. At the
same time the fully qualified notation will work:
document.forms[''myForm''].elements[''radio[0]'']


VK wrote:

On May 25, 3:12 pm, Stanimir Stamenkov <s7a...@netscape.netwrote:

><form name="myForm" action="..."<p><input type="text"
name="myElem"></p</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms[''myForm''].elements[''myElem'']

But I have also seen the following:

document.forms[''myForm''].myElem


The latter is a shortcut accessor to the same element.

It sa reference to the same element _object_, if that.

Most of the time the shortcut form can be used to preserve your keyboard
and your finger tips :-) It is not the case when the form control name
doesn''t conform with Javascript valid identifier rules.

Wrong. The proprietary referencing allows

document.forms[''myForm'']["myElem[]"]

as well.

The reason for using the standards-compliant approach over the proprietary
one is that the latter is the *proprietary* one. Proprietary approaches
should be avoided, and should only serve as a fallback for
standards-compliant approaches because, theoretically, by definition they
could break any minute the code is exposed to another, previously unknown,
user agent.
PointedEars
--
Anyone who slaps a ''this page is best viewed with Browser X'' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


这篇关于document.forms [表格名称] .elemName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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