有本书上说用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" />
    <input type="button" name="button1" />
    <input type="button" name="button2" />
</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 />
<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>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-03-06
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-09-06
  • 2022-02-01
相关资源
相似解决方案