"&的getAttribute QUOT;返回子元素而不是...? [英] "getAttribute" returns a child element instead of ...?
问题描述
嗨
我有一个看起来像这样的页面:
< form name =" kuku1" action =" anotherpage.html" >
<输入名称="名称">
<输入名称=" kuku2">
< / form>
据我所知,getAttribute和应该返回一个
元素属性的字符串值。
document.forms [0] .getAttribute(" action")确实返回字符串
" anotherpage.html"
document.forms [0] .action也会返回该字符串
但是,文件.forms [0] .getAttribute(" name")不返回
字符串" kuku1",但它返回第一个输入对象。
在类似的way,document.forms [0] .getAttribute(" kuku2")返回
第二个输入元素,而不是null对象(或空字符串)as i
会期待。
这是一个错误吗?它是一个定义的行为吗?
我怎样才能得到表格的名称???
< blockquote>
Noa写道:
嗨
我有一个看起来像这样的页面:
< form名称= QUOT; kuku1" action =" anotherpage.html" >
< input name =" name">
< input name =" kuku2">
< / form>
As据我所知,getAttribute应返回
元素属性的字符串值。
document.forms [0] .getAttribute(" action")确实返回字符串
anotherpage。 html"
document.forms [0] .action也将返回该字符串
然而,document.forms [0] .getAttribute(" name")不会返回
string" kuku1",但它返回第一个输入对象。
以类似的方式,document.forms [0] .getAttribute(" kuku2")返回
第二个输入元素,而不是我想要的null对象(或空字符串)。
这是一个bug吗?
不,只是错误使用正确的工具。现在放弃它。
我怎样才能得到表格的名称???
alert(document.forms [0] .name);
alert(document.forms [0] .action);
alert(document.forms [0] .method);
alert(document.forms [0] .enctype);
alert(document.forms [0] .elements [0] .name);
alert(document.forms [0] .elements [1] .name);
.....
> "诺亚" < NL **** @ jacada.com>写道:新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ....
你好
我有一个看起来像这样的页面:
< form name =" kuku1" action =" anotherpage.html" >
< input name =" name">
< input name =" kuku2">
< / form>
As据我所知,getAttribute应返回
元素属性的字符串值。
document.forms [0] .getAttribute(" action")确实返回字符串
anotherpage。 html"
document.forms [0] .action也将返回该字符串
然而,document.forms [0] .getAttribute(" name")不会返回
string" kuku1",但它返回第一个输入对象。
以类似的方式,document.forms [0] .getAttribute(" kuku2")返回
第二个输入元素,而不是一个null对象(或一个空的
字符串)正如我所料。
这是一个bug吗?它是一个定义的行为吗?
我怎样才能得到表格的名称?
如果它改变了怎么办?输入名称= "名称"> to< input name =" _name">?
-
BootNic 2006年1月25日星期三上午10:18
每当我关上现实的门时,它都透过窗户进来。
* Jennifer Unlimited *
>
Noa写道:
我有一个看起来像这样的页面:
< form name =" kuku1" action =" anotherpage.html" >
< input name =" name">
< input name =" kuku2">
< / form>
As据我所知,getAttribute应返回
元素属性的字符串值。
document.forms [0] .getAttribute(" action")确实返回字符串
anotherpage。 html"
document.forms [0] .action也将返回该字符串
然而,document.forms [0] .getAttribute(" name")不会返回
string" kuku1",但它返回第一个输入对象。
确切地说,是对第一个(HTML)输入(元素)对象的引用。
以类似的方式,document.forms [0]。 getAttribute(" kuku2")返回
第二个输入元素,而不是我希望的空对象(或空字符串)。
null值和空字符串是非常不同的东西。你应该
不要指望在指定
字符串的地方返回'object''类型如'null''的值,就像它在这里一样。
这是一个错误吗?
是的,确实你在Element :: getAttribute()
实现中发现了另一个错误,并且你提供了另一个不应该使用它的原因< HTML DOM中的
以及为什么应该使用直接属性访问,
直到另行通知为止。
它是一个定义的行为?
不,不是。 Element :: getAttribute()旨在返回元素属性的值
,该元素由DOM中相应的
元素对象表示。这就是HTMLFormElement对象
在这里代表`form''元素。
我怎样才能获得表单的名称???
不要将任何表单控件命名为name,确切地说永远不要使用标识符
属性为`form''元素或属性( HTML)表单(元素)
对象作为表单控件的名称或ID(如果它是`form'的子元素'
元素)。但是,您不太可能需要表单的名称或
首先需要为表单命名;尝试使用'this''参考
代替。
PointedEars
Hi
I have a page that looks like that:
<form name="kuku1" action ="anotherpage.html" >
<input name="name">
<input name="kuku2">
</form>
As far as i know, "getAttribute" should return a string value of an
elements'' attribute.
document.forms[0].getAttribute("action") indeed returns the string
"anotherpage.html"
document.forms[0].action will also return that string
However, document.forms[0].getAttribute("name") does not return the
string "kuku1", but it returns the first input object.
In a similar way , document.forms[0].getAttribute("kuku2") returns the
second input element, and not a null object (or an empty string) as i
would expect.
Is it a bug? is it a defined behavoiur?
And how can i get the name of the form ???
Noa wrote:Hi
I have a page that looks like that:
<form name="kuku1" action ="anotherpage.html" >
<input name="name">
<input name="kuku2">
</form>
As far as i know, "getAttribute" should return a string value of an
elements'' attribute.
document.forms[0].getAttribute("action") indeed returns the string
"anotherpage.html"
document.forms[0].action will also return that string
However, document.forms[0].getAttribute("name") does not return the
string "kuku1", but it returns the first input object.
In a similar way , document.forms[0].getAttribute("kuku2") returns the
second input element, and not a null object (or an empty string) as i
would expect.
Is it a bug?
No, just wrong usage of right tools. Drop it for now.
And how can i get the name of the form ???
alert(document.forms[0].name);
alert(document.forms[0].action);
alert(document.forms[0].method);
alert(document.forms[0].enctype);
alert(document.forms[0].elements[0].name);
alert(document.forms[0].elements[1].name);
.....
> "Noa" <nl****@jacada.com> wrote:news:11**********************@f14g2000cwb.googlegr oups.com....
Hi
I have a page that looks like that:
<form name="kuku1" action ="anotherpage.html" >
<input name="name">
<input name="kuku2">
</form>
As far as i know, "getAttribute" should return a string value of an
elements'' attribute.
document.forms[0].getAttribute("action") indeed returns the string
"anotherpage.html"
document.forms[0].action will also return that string
However, document.forms[0].getAttribute("name") does not return the
string "kuku1", but it returns the first input object.
In a similar way , document.forms[0].getAttribute("kuku2") returns
the second input element, and not a null object (or an empty
string) as i would expect.
Is it a bug? is it a defined behavoiur?
And how can i get the name of the form ???
What would happen if it change <input name="name"> to <input name="_name">?
--
BootNic Wednesday, January 25, 2006 10:18 AM
Every time I close the door on reality it comes in through the windows.
*Jennifer Unlimited*
Noa wrote:
I have a page that looks like that:
<form name="kuku1" action ="anotherpage.html" >
<input name="name">
<input name="kuku2">
</form>
As far as i know, "getAttribute" should return a string value of an
elements'' attribute.
document.forms[0].getAttribute("action") indeed returns the string
"anotherpage.html"
document.forms[0].action will also return that string
However, document.forms[0].getAttribute("name") does not return the
string "kuku1", but it returns the first input object.
To be exact, a reference to the first (HTML)Input(Element) object.
In a similar way , document.forms[0].getAttribute("kuku2") returns the
second input element, and not a null object (or an empty string) as i
would expect.
The `null'' value and the empty string are very different things. You should
not expect that a value of `object'' type like `null'' is returned where a
string is specified, as it is here.
Is it a bug?
Yes, indeed you have discovered another bug in an Element::getAttribute()
implementation, and you provided another reason why it should not be used
in the HTML DOM and why direct property accesses should be used instead,
until further notice.
is it a defined behavoiur?
No, it is not. Element::getAttribute() is designed to return the value
of the attribute of the element that is represented by the respective
Element object in the DOM. That would the the HTMLFormElement object
representing the `form'' element here.
And how can i get the name of the form ???
Do not name any form control "name", to be exact never use an identifier
of an attribute of `form'' elements or a property of (HTML)Form(Element)
objects as name or ID of a form control (if it is child of a `form''
element). However, it is unlikely that you need the name of the form or
need to name the form in the first place; try to use the `this'' reference
instead.
PointedEars
这篇关于"&的getAttribute QUOT;返回子元素而不是...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!