document.getElementById 的一个问题
代码如下
<!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">
<head>
<script type="text/javascript">
function getValue()
{
alert(document.getElementById("myHeader"))
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getValue()">This is a header</h1>
</body>
</html>
IE8测试:结果是[object HTMLHeadingElement], IE7测试结果:[object],IE6测试结果:[object] 其他版本浏览器结果都是:[object]。上述代码如果将
<!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">换成<html>。IE测试结果也是:[object]。请问各位大侠,不管在任何浏览器上,如何让alert显示的是[object HTMLHeadingElement]呢?
<!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">
<head>
<script type="text/javascript">
function getValue()
{
alert(document.getElementById("myHeader"))
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getValue()">This is a header</h1>
</body>
</html>
IE8测试:结果是[object HTMLHeadingElement], IE7测试结果:[object],IE6测试结果:[object] 其他版本浏览器结果都是:[object]。上述代码如果将
<!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">换成<html>。IE测试结果也是:[object]。请问各位大侠,不管在任何浏览器上,如何让alert显示的是[object HTMLHeadingElement]呢?
...全文
相关推荐
浅谈vue中document.getElementById()拿到的是原值的问题
"Vue.js中document.getElementById()返回旧值的问题及解决方案"在Vue.js应用程序中,遇到`document.getElementById()`返回旧值的问题,通
解决 firefox 不支持 document.all的方法
解决 Firefox 不支持 document.all 的方法在 Web 开发中,我们经常会遇到浏览器的兼容性问题,其中一个常见的问题就是 Firefox 不支持 document.all 对象。
各浏览器对document.getElementById等方法的实现差异解析
(document, arguments); }; })(document.getElementById); ``` 这里我们创建了一个匿名函数,它接收`document.getElementById`
document.getElementById()报错处理[源码]
在进行网页开发的过程中,document.getElementById() 是一个被频繁使用的 JavaScript 方法,其作用是通过元素的ID来获取对应的DOM节点。
document.getElementById获取控件对象为空的解决方法
例如,`document.getElementById('mes')` 将返回ID为 'mes' 的第一个元素。如果页面中没有与该ID匹配的元素,则返回 `null`。


