Firefox不支持input手动填写后的getAttribute("value"),只能用.value(Firefox 3.5.5 Windows)。bug?

有本书上说用XML DOM,用getAttribute("value") ,别用.value 。

 .value 也是符合W3C标准的,属于 HTML DOM 。

 

环境: Firefox 3.5.5 Windows

在Firefox 中,手动填写input元素,使用getAttribute("value")无法得到填写的值。

所以只能用.value,没想到firefox也存在这种问题。这属于firefox对XML DOM支持的不够?bug?

测试代码如下:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="yue-Hans-cn" lang="yue-Hans-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>it works..............</title>
</head>
<body>
<form action="./" method="get">
    <input type="text" name="address" id="address" />
    <input type="button" name="button1" id="button1" value="getAttribute('value')" onclick="alert(document.getElementById('address').getAttribute('value'));" />
    <input type="button" name="button2" id="button2" value=".value" onclick="alert(document.getElementById('address').value);" />
</form>
</body>
</html>

 

 

还有这篇文章的代码:http://updatepanel.net/2008/12/31/more-on-getattribute-setattribute-and-the-value-attribute/

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns=" "http://www.w3.org/1999/xhtml">
<head>
<title>More on getAttribute() and setAttribute()</title>
</head>
<body>
<input id="TextBox1" type="text" value="123" />
<input type="button" value="alert(element.getAttribute('value'));" onclick="alert(document.getElementById('TextBox1').getAttribute('value'));" />
<input type="button" value="alert(element.value);" onclick="alert(document.getElementById('TextBox1').value);" />
<ol>
<li><input type="button" value="element.setAttribute('value', '456');" onclick="document.getElementById('TextBox1').setAttribute('value', '456');" /></li>
<li>Enter 'abc' into the text box.</li>
<li><input type="button" value="element.value = '789';" onclick="document.getElementById('TextBox1').value = '789';" /></li>
<li><input type="button" value="element.setAttribute('value', 'xyz');" onclick="document.getElementById('TextBox1').setAttribute('value', 'xyz');" /></li>
</ol>
</body>
</html>

 

posted @ 2009-12-10 18:09  sink_cup  阅读(1153)  评论(0编辑  收藏  举报
Creative Commons License

本站原创作品采用知识共享署名 3.0许可协议进行许可。