JavaScript中document.getElementById和document.write
1、操作HTML元素
JavaScript访问某个HTML元素,可以使用document.getElementById(id)方法。
eg:
- <!DOCTYPE html>
- <html>
- <body>
- <p id="demo">Hello</p>
- <script>
- document.getElementById("demo").innerHTML="Hello world";
- </script>
- </body>
- </html>
2、写到文档输出
JavaScript写到文档输出,可以使用document.write('HTML内容')方法。
eg:
- <!DOCTYPE html>
- <html>
- <body>
- <script>
- document.write("<p>Hello world</p>");
- </script>
- </body>
- </html>
注意:
请使用 document.write() 仅仅向文档输出写内容。
如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖:
<!DOCTYPE html>
<html>
<body>
<p>Hello world</p>
<button οnclick="myFunction()">点击这里</button>
<script>
function myFunction(){
document.write("糟糕!消失了。");
}
</script>
</body>
</html>
转载于:https://www.cnblogs.com/xiajiejie/p/9866581.html
JavaScript中document.getElementById和document.write相关推荐
- document.getElementById()和document.forms[0].submit()
下午,做一个jsp文件,涉及到document.getElementById()以及document.forms[0].submit()的使用,折腾了好长时间. 1.document.getEleme ...
- (COPY)document.all和document.getElementById用法 document.all用法:
(COPY)document.all和document.getElementById用法 document.all用法: <html> <body> < ...
- document.getElementById与document.getElementsById的区别
document.getElementById 是用Id选择元素,一个Id只对应一个元素. document.getElementsById 是用元素名称选择元素一个元素名称可能有很多元素,取的是集, ...
- javascript中的getElementById、getElementsByName、getElementByTagName详解
getElementById.getElementsByTageName.getElementsByName的区别 1.getElementById根据指定Id得到html元素,所以只能得到唯一的ht ...
- javascript 中的window, document, screen都有什么区别?
谷歌之后,从stackoverflow上找到的高赞答案: https://stackoverflow.com/questions/9895202/what-is-the-difference-betw ...
- document.getElementById 学习总结
document.getElementById获取控件对象为空的解决方法 1.下面是一个简单的例子,页面加载时显示一段信息 代码如下: <%@ page language="java& ...
- document.getElementById(billNo)的作用
// 代码段 <script type="text/javascript">/* 自动生成随机账单 */function getCKD(){var d=document ...
- document.write vs document.getElementById
document.write: JavaScript中对document.open所开启的文档流(document stream操作的API方法,它能够直接在文档流中写入字符串,一旦文档流已经关闭,那 ...
- document.getElementById()方法使用
原文地址为: document.getElementById()方法使用 document.getElementById使用 语法:oElement = document .getElementByI ...
- 各浏览器对document.getElementById等方法的实现差异
所有Web前端同仁对 document.getElementById 都非常熟悉了.开发过程中经常需要用其获取页面id为xx的元素,自从元老级JS库Prototype流行后,都喜欢这么简写它 // 方 ...
最新文章
- 初始化HashMap的默认值——阿里巴巴编码规范系列
- 再一次站在捆绑销售风口的携程该何去何从?
- java 顺序表的实现_顺序表的简单实现(Java)
- 产品读书《创新者的窘境》
- 匹配表情emoji 正则_新版Emoji表情过滤
- 阿里云服务器桌面版配置
- mysql插入表情_向MySQL数据库中插入带emoji表情符的数据时报错
- Django新手入门(五)——Models详解
- mysql升级8.0后,项目遇到的坑
- php批量处理图片大小,wps如何批量处理图片大小
- EBS 报表开发:标准报表Text输出改为XML输出
- C++课程基础语法小结
- storm trident
- 设计模式之SOLID原则
- 天使湖北武汉汇美是骗子T
- XBee3如何设置“自定义默认值”
- Linux开发工具vim篇
- python 课程设计 夏敏捷_Python课程设计 微课视频版
- 为什么要使用堆栈? sp和fp的解释
- python决策树分类预测_数据分类预测之python决策树
热门文章
- 【渝粤教育】国家开放大学2018年春季 8636-22T实用心理学 参考试题
- 【渝粤教育】国家开放大学2018年春季 0089-21DInternet和Intranet应用 参考试题
- [渝粤教育] 西南科技大学 经济法概论 在线考试复习资料2021版
- Numpy系列(七)求解线性方程组、计算逆矩阵求解线性方程组
- 结构化数据与非结构化数据理解
- http://me.rice.edu/~akin/
- Linux中的samba服务和ftp服务
- django drf 改变retrive的pk查询字段
- springboot读取application.properties中自定义配置
- python的重试库tenacity用法以及类似库retry、requests实现