我不明白 [object HTMLDivElement] 这个算什么,报错吗?
为什么不是输出那个DIV?
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>匿名函数</title>
<style>
#div1 {
width: 100px;
height: 100px;
background-color: black;
color: white;
}
</style>
</head>
<script>
window.onload = function() {
var avc = document.getElementById("div1");
document.write(avc);
} var a = function() {
alert("好困呐!!!!!!!!");
} a();
</script> <body>
<div id="div1">搜狗拼音输入法</div>
</body></html>
为什么不是输出那个DIV?
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>匿名函数</title>
<style>
#div1 {
width: 100px;
height: 100px;
background-color: black;
color: white;
}
</style>
</head>
<script>
window.onload = function() {
var avc = document.getElementById("div1");
document.write(avc);
} var a = function() {
alert("好困呐!!!!!!!!");
} a();
</script> <body>
<div id="div1">搜狗拼音输入法</div>
</body></html>
解决方案 »
- 急求,一个关于JS兼容FF浏览器的问题
- 点击增加多个div后,鼠标点击哪个div层上面,就删除哪个,不点击不删除,显示提示
- <object id='Catia' classid='CLSID:78D0454C-3ABF-45A0-865E-D57DCEF83D73' 问题
- 这个效果如何实现,多谢
- js 非空验证 text
- 请教如何能实现鼠标放图片上图片有逐渐变大变清晰的过程,图片还能被关闭
- vml生成的图片导入word 怎么导阿〉? 求救!
- 帮帮我吧。新手问题。
- 急!页面跳转刷新问题
- 求表格中一列的所有的数值相加的和的问题!!!特急!!求救!!!!
- json数组对象,如何取出其中一部分,组成新数组对象
- 正则表达式/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/
建议使用console.log()输出这种,F12可以调试。也可以点开对象,查看所有属性和方法
返回的是div元素的全称
如果要获取div元素的内容请添加 .innerHTML eg:var avc = document.getElementById("div1").innerHTML
document.write(avc);
改为
var avc = document.getElementById("div1").value;
document.write(avc.value);