博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript中document.getElementById和document.write的区别
阅读量:4705 次
发布时间:2019-06-10

本文共 503 字,大约阅读时间需要 1 分钟。

document.getElementById和document.write都是输出

但document.write仅仅向文档输出写内容。如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖

而document.getElementById("demo").innerHTML= 改变的只是局部属性。

例如代码:

<!DOCTYPE html>

<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph.</p>
<button οnclick="myFunction()">点击这里</button>
<script>
function myFunction()
{
document.write("糟糕!文档消失了。");
}
</script>
</body>
</html>

 

点击后变成:

 

 

(来源于: http://www.w3school.com.cn/js/js_shuchu.asp)

 

转载于:https://www.cnblogs.com/luoyiling/p/9895064.html

你可能感兴趣的文章
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
memcached 细究(三)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>
[NYIST15]括号匹配(二)(区间dp)
查看>>
json_value.cpp : fatal error C1083: 无法打开编译器生成的文件:No such file or directory
查看>>
洛谷 P1101 单词方阵
查看>>