Firefox不支援input手動填寫後的getAttribute(“value”),只能用.value(Firefox 3.5.5 Windows)。bug?

來源:互聯網
上載者:User

有本書上說用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>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.