从输入中查找表单元素 [英] Finding a Form Element from an Input

查看:79
本文介绍了从输入中查找表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个输入元素的ID,如何在javascript中找到输入'

FORM?


基本上,给定一个输入'dom id,我想在输入所在的表单的

onSubmit中插入一些东西。我想避免让

用户拥有如果可能的话,提交表格的ID。


如果我的问题不清楚,请告诉我......谢谢!


Kel

Hi, if I had the ID of an input element, how can I find the input''s
FORM in javascript?

Basically, given a input''s dom id, I want to insert something in the
onSubmit of the Form that that input is in. I want to avoid making the
user have to submit the form''s id if possible.

Let me know if my question is unclear...thanks!

Kel

推荐答案

于2006年7月30日在comp.lang.javascript中写道
wrote on 30 jul 2006 in comp.lang.javascript:

如果我有一个输入元素的ID,我怎样才能在javascript中找到输入'

FORM?
Hi, if I had the ID of an input element, how can I find the input''s
FORM in javascript?



< form id = f name = ff>

< input id = x>

< ; / form>


< script type =''text / javascript''>

var x = document.getElementById(''x'' )

alert(x.form.id)//返回f

alert(x.form.name)//返回ff

< ; / script>

-

Evertjan。

荷兰。

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

<form id=f name=ff>
<input id=x>
</form>

<script type=''text/javascript''>
var x = document.getElementById(''x'')
alert(x.form.id) // returns f
alert(x.form.name) // returns ff
</script>
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


很好...我不敢尝试只查看输入的属性

元素调试器!谢谢:)


Kel


Evertjan。写道:
Nice...Silly of me to not try just viewing the properties of the input
element in a debugger! Thanks :)

Kel

Evertjan. wrote:

于2006年7月30日在comp.lang.javascript中写道

如果我有一个输入元素的ID,我怎样才能在javascript中找到输入'

FORM?
Hi, if I had the ID of an input element, how can I find the input''s
FORM in javascript?



< form id = f name = ff>

< input id = x>

< ; / form>


< script type =''text / javascript''>

var x = document.getElementById(''x'' )

alert(x.form.id)//返回f

alert(x.form.name)//返回ff

< ; / script>


-

Evertjan。

荷兰。

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


<form id=f name=ff>
<input id=x>
</form>

<script type=''text/javascript''>
var x = document.getElementById(''x'')
alert(x.form.id) // returns f
alert(x.form.name) // returns ff
</script>
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


" Evertjan。 < ex ************** @interxnl.netwrites:
"Evertjan." <ex**************@interxnl.netwrites:

< form id = f name = ff>
<form id=f name=ff>



只是为了迂腐(不能让错误被取消评论)

name和id 形式的属性。元素必须与有效HTML格式相同。

< URL:http://www.w3.org/TR/html4/struct/links.html#h- 12.2.3>


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

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

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

Just to be pedantic (can''t let an error go uncommented :)
the "name" and "id" attributes of a "form" element must be
identical in valid HTML.
<URL:http://www.w3.org/TR/html4/struct/links.html#h-12.2.3>

/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.''


这篇关于从输入中查找表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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