常见问题主题 - 如何获取表单控件的值? [英] FAQ Topic - How do I get the value of a form control?

查看:51
本文介绍了常见问题主题 - 如何获取表单控件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

常见问题解答主题 - 如何获取表单控件的值?

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


在HTML文档中,命名表单可以称为命名

属性的? document.forms?集合和命名表单

控件可以被称为表单'

元素集合的命名属性:


var frm = document.forms [" formname"];

var contrl = frm.elements [" elementname"];


(字符串)这些控件的value属性可以直接从元素中读取

: -


var value = contrl.value;

var value =(+ contrl.value); //字符串到数字:见4.21


一些例外情况是:


第一例外:控件是SELECT元素的位置,<需要支持旧版浏览器(如NN4)的
支持:

var value = contrl.options [contrl.selectedIndex] .value;


第二个异常:多个控件共享同一个名称,

,例如单选按钮。它们以集合形式提供

并需要额外处理。有关详细信息,请参阅: -

http ://www.jibbering.com/faq/faq_notes/form_access.html


第三例外:大多数当前浏览器没有的文件输入

允许读取type =" file"以有用的方式输入元素。

===

这样的发布每天自动发送一次。他们的b
目标是回答重复的问题,并将内容提供给社区进行持续评估/改进。完整的

comp.lang.javascript常见问题解答位于 http: //jibbering.com/faq/index.html

FAQ工作人员是一群志愿者。

解决方案

FAQ服务器于2007年2月19日在comp.lang.javascript中写道


在HTML文档中,命名表格可以称为

属性的? document.formsˉ集合和命名表单

控件可以被称为表单'

元素集合的命名属性:



我不会使用表单控件但是表单元素。


在所有DOM使用之后:


document.forms [''..'']。元素[''..'']


不要让可怕的MS asp.net术语啜饮这个FAQ。


-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点数)


2月19日上午9:55,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:


FAQ服务器于2007年2月19日在comp.lang.javascript中写道


>在HTML文档中,命名表单可以称为 - document.formsˉ集合的命名
属性,命名表单
控件可以称为表单'
元素集合的命名属性:



我不会使用表单控件但是表单元素。


在所有DOM使用之后:


document.forms [''..'']。元素[''..'']


不要让可怕的MS asp.net术语啜饮这个FAQ。



" Control"是来自W3C HTML规范的术语,指的是

TEXTAREA,INPUT,SELECT和BUTTON元素(以及假设OBJECT

元素)。以前有人建议使用元素。可能是因为所有HTML元素都在DOM中用

元素表示元素接口。

Richard。


Richard Cornford于2007年2月19日在comp.lang.javascript写了


2月19日上午9:55,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:


> FAQ服务器于2007年2月19日在comp.lang.javascript中写道


>>在HTML文档中,命名表单可以称为 - document.formsˉ集合的命名
属性,并命名表单
控件可以被称为表单'
元素集合的命名属性:


我不会使用表单控件。但是表单元素。

在所有DOM使用之后:

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

不要让可怕的MS asp.net术语啜饮这个FAQ。



" Control"是来自W3C HTML规范的术语,指的是

TEXTAREA,INPUT,SELECT和BUTTON元素(以及假设OBJECT

元素)。以前有人建议使用元素。因为所有HTML元素都在DOM中表示,实现了Element接口的

元素,所以可能会因为b $ b而感到困惑。



如果我知道的话,我会反对。


也许是输入元素?


或许扔掉一个开关,

但输入或丢弃文字并不满足

我对控制的理解。

-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)


-----------------------------------------------------------------------
FAQ Topic - How do I get the value of a form control?
-----------------------------------------------------------------------

In HTML documents, named forms may be referred to as named
properties of the ? document.forms ? collection, and named form
controls may be referred to as named properties of the form''s
elements collection:

var frm = document.forms["formname"];
var contrl = frm.elements["elementname"];

The (string) value property of such controls can be read
directly from the element:-

var value = contrl.value;
var value = (+contrl.value); //string to number: see 4.21

Some exceptions would be:

First Exception: Where the control is a SELECT element, and
support for older browsers, such as NN4, is required:

var value = contrl.options[contrl.selectedIndex].value;

Second Exception: Where several controls share the same name,
such as radio buttons. These are made available as collections
and require additional handling. For more information, see:-

http://www.jibbering.com/faq/faq_notes/form_access.html

Third Exception: File Inputs where most current browsers do not
allow the reading of type="file" input elements in a way that is useful.
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.

解决方案

FAQ server wrote on 19 feb 2007 in comp.lang.javascript:

In HTML documents, named forms may be referred to as named
properties of the ? document.forms ˉ collection, and named form
controls may be referred to as named properties of the form''s
elements collection:

I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms[''..''].elements[''..'']

Do not let terrible MS asp.net terminology sip into this FAQ.

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


On Feb 19, 9:55 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:

FAQ server wrote on 19 feb 2007 in comp.lang.javascript:

>In HTML documents, named forms may be referred to as named
properties of the - document.forms ˉ collection, and named form
controls may be referred to as named properties of the form''s
elements collection:


I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms[''..''].elements[''..'']

Do not let terrible MS asp.net terminology sip into this FAQ.

"Control" is terminology from the W3C HTML specification, referring to
TEXTAREA, INPUT, SELECT and BUTTON elements (and hypothetically OBJECT
elements). Previously it has been suggested that "element" may be
confusing because all HTML elements are represented in the DOM with
elements implementing the Element interface.

Richard.


Richard Cornford wrote on 19 feb 2007 in comp.lang.javascript:

On Feb 19, 9:55 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:

>FAQ server wrote on 19 feb 2007 in comp.lang.javascript:

>>In HTML documents, named forms may be referred to as named
properties of the - document.forms ˉ collection, and named form
controls may be referred to as named properties of the form''s
elements collection:


I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms[''..''].elements[''..'']

Do not let terrible MS asp.net terminology sip into this FAQ.


"Control" is terminology from the W3C HTML specification, referring to
TEXTAREA, INPUT, SELECT and BUTTON elements (and hypothetically OBJECT
elements). Previously it has been suggested that "element" may be
confusing because all HTML elements are represented in the DOM with
elements implementing the Element interface.

I would have objected if I had known.

Perhaps "input element"?

Throwing a switch perhaps,
but entering or dropping text does not satisfy
my understanding of controlling.
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于常见问题主题 - 如何获取表单控件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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