当前位置:网站首页>document对象
document对象
2022-06-11 09:14:00 【夺笋123】
我们知道,浏览器中每个窗口就是一个window对象,这个窗口里面的HTML文档就是一个document对象,这样我们就可以通过该对象来操作页面中的所有元素,这些操作被称为"DOM"(文档对象模型)
document对象属性
| 属性 | 说明 |
|---|---|
| document.title | 返回当前文档的标题。 |
| document.body | 返回文档的body元素 |
| document.URL | 返回文档完整的URL |
| document.images | 返回对文档中所有 Image 对象引用。 |
| document.links | 返回对文档中所有 Area 和 Link 对象引用(获取所有a元素)。 |
| document.cookie | 设置或返回与当前文档有关的所有 cookie。 |
| document.referrer | 返回载入当前文档的文档的 URL。 |
关于document.referrer
该属性经常用于统计用户是通过什么方式访问某网站的。
假设页面A设置了一个指向页面B的超链接,那么当我们通过该超链接进入页面B时,在该页面就可以使用document.referrer获得页面A的地址。
document对象方法
| 方法 | 描述 |
|---|---|
| getElementById() | 通过id定位一个元素 |
| getElementsByTagName() | 通过标签名定位一个元素 |
| getElementByClassName() | 通过类名定位一个元素 |
| querySelector(“选择器”) | 选取满足条件的第一个元素 |
| querySelectorAll(“选择器”) | 选取满足条件的所有元素 |
| getElementsByName() | 通过name属性定位元素 |
向页面输出内容
document.write("输出内容")
document.writeIn("输出内容")
上述两者的区别是,后者会在输出内容后面多加一个换行符"\n",下面我们通过一个例子观察两者区别
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>这是一个html5 demo</title>
</head>
<body>
<script> document.writeln("AAA") document.writeln("BBB") document.writeln("CCC") document.writeln("DDD") document.writeln("<hr/>") document.write("AAA") document.write("BBB") document.write("CCC") document.write("DDD") </script>
</body>
</html>
Chrome浏览器运行结果
边栏推荐
- Type-C Bluetooth speaker single port rechargeable OTG solution
- Console you don't know
- 【分享】企業如何進行施行規劃?
- [TiO websocket] v. TiO websocket server counts the number of online people
- What are the types of garment ERP system in the market?
- 面试题 17.10. 主要元素
- [scheme development] sphygmomanometer scheme pressure sensor sic160
- 报错[error] input tesnor exceeds available data range [NeuralNetwork(3)] [error] Input tensor ‘0‘ (0)
- 【服装ERP】施行在项目中的重要性
- Machine learning notes - in depth Learning Skills Checklist
猜你喜欢

机器学习笔记 - 深度学习技巧备忘清单

CUMT learning diary - theoretical analysis of uCOSII - Textbook of Renzhe Edition

考研數學 【數列極限證明題】題型方法總結

Control statement if switch for while while break continue

Talk about reading the source code

Thread theory

机器学习笔记 - 卷积神经网络备忘清单

OpenCV OAK-D-W广角相机测试

Detailed explanation of this and static

山东大学增强现实实验四
随机推荐
Tissu. JS définit dynamiquement la taille de la police
ArcGIS 10.9.1 地质、气象体元数据处理及服务发布调用
OpenCV OAK-D-W广角相机测试
[TiO websocket] v. TiO websocket server counts the number of online people
[share] how do enterprises carry out implementation planning?
Exclusive interview - dialogue on open source Zhai Jia: excellent open source projects should be seen by more people. I am honored to participate in them
Flask (I) - quick start
Type-C扩展坞自适应供电专利维权案例
The mobile terminal page uses REM for adaptation
Day39 process object and other method mutexes
Telecommuting best practices and Strategies
Openstack explanation (21) -- installation and configuration of neutron components
Comparison and introduction of OpenCV oak cameras
Flask (VII) - static file
[TiO websocket] IV. the TiO websocket server implements the custom cluster mode
1854. 人口最多的年份
Control statement if switch for while while break continue
Version mismatch between installed deeply lib and the required one by the script
Flask (II) - route
服装ERP:企业如何进行施行规划?