关于document.write(来自网络)

本文详细介绍了如何使用DOM(Document Object Model)进行网页元素的操作,包括设置和读取对象属性、动态生成HTML对象、处理页面事件等。涵盖了document对象的属性与方法,如document.write(), document.createElement(), document.getElementById()等,以及body、location、selection子对象的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对象属性:

document.title                 //设置文档标题等价于HTML的<title>标签
document.bgColor               //设置页面背景色
document.fgColor               //设置前景色(文本颜色)
document.linkColor             //未点击过的链接颜色
document.alinkColor            //激活链接(焦点在此链接上)的颜色
document.vlinkColor            //已点击过的链接颜色
document.URL                   //设置URL属性从而在同一窗口打开另一网页
document.fileCreatedDate       //文件建立日期,只读属性
document.fileModifiedDate      //文件修改日期,只读属性
document.fileSize              //文件大小,只读属性
document.cookie                //设置和读出cookie
document.charset               //设置字符集 简体中文:gb2312
----------------------------
常用对象方法:

document.write()                      //动态向页面写入内容
document.createElement(Tag)           //创建一个html标签对象
document.getElementById(ID)           //获得指定ID值的对象
document.getElementsByName(Name)      //获得指定Name值的对象
document.body.appendChild(oTag)
========================================================================
body-主体子对象

document.body                   //指定文档主体的开始和结束等价于<body></body>
document.body.bgColor           //设置或获取对象后面的背景颜色
document.body.link              //未点击过的链接颜色
document.body.alink             //激活链接(焦点在此链接上)的颜色
document.body.vlink             //已点击过的链接颜色
document.body.text              //文本色
document.body.innerText         //设置<body>...</body>之间的文本
document.body.innerHTML         //设置<body>...</body>之间的HTML代码
document.body.topMargin         //页面上边距
document.body.leftMargin        //页面左边距
document.body.rightMargin       //页面右边距
document.body.bottomMargin      //页面下边距
document.body.background        //背景图片
document.body.appendChild(oTag) //动态生成一个HTML对象
----------------------------
常用对象事件:

document.body.onclick="func()"              //鼠标指针单击对象是触发
document.body.onmouseover="func()"          //鼠标指针移到对象时触发
document.body.onmouseout="func()"           //鼠标指针移出对象时触发
========================================================================
location-位置子对象:

document.location.hash          // #号后的部分
document.location.host          // 域名+端口号
document.location.hostname      // 域名
document.location.href          // 完整URL
document.location.pathname      // 目录部分
document.location.port          // 端口号
document.location.protocol      // 网络协议(http:)
document.location.search        // ?号后的部分
----------------------------
常用对象事件:

documeny.location.reload()          //刷新网页
document.location.reload(URL)       //打开新的网页
document.location.assign(URL)       //打开新的网页
document.location.replace(URL)      //打开新的网页
========================================================================
selection-选区子对象
document.selection
========================================================================
images集合(页面中的图象):
----------------------------
a)通过集合引用
document.images                 //对应页面上的<img>标签
document.images.length          //对应页面上<img>标签的个数
document.images[0]              //第1个<img>标签          
document.images[i]              //第i-1个<img>标签
----------------------------
b)通过name属性直接引用
<img name="oImage">
document.images.oImage          //document.images.name属性
----------------------------
c)引用图片的src属性
document.images.oImage.src      //document.images.name属性.src
----------------------------
d)创建一个图象
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
同时在页面上建立一个<img>标签与之对应就可以显示

forms集合(页面中的表单):
----------------------------
a)通过集合引用
document.forms                     //对应页面上的<form>标签
document.forms.length              //对应页面上<form>标签的个数
document.forms[0]                  //第1个<form>标签
document.forms[i]                  //第i-1个<form>标签
document.forms[i].length           //第i-1个<form>中的控件数
document.forms[i].elements[j]      //第i-1个<form>中第j-1个控件
----------------------------
b)通过标签name属性直接引用
<form name="Myform"><input name="myctrl"></form>
document.Myform.myctrl             //document.表单名.控件名
----------------------------
c)访问表单的属性
document.forms[i].name             //对应<form name>属性
document.forms[i].action           //对应<form action>属性
document.forms[i].encoding         //对应<form enctype>属性
document.forms[i].target           //对应<form target>属性
document.forms[i].appendChild(oTag) //动态插入一个控件

转载于:https://www.cnblogs.com/weinixiong/p/9892292.html

async onDownloadStart () { console.log('开始下载...') this.$message.info('开始下载文件') try { const res = await userexport([]) // 打印 res 查看实际的 Blob 数据 console.log(res) const filename = '用户信息.xlsx' // const contentType = res.headers?.['content-type'] || 'application/octet-stream' const contentType = res.type const blob = new Blob([res], { type: contentType }) const url = window.URL.createObjectURL(blob) const dom = document.createElement('a') dom.style.display = 'none' dom.href = url dom.setAttribute('download', filename) document.body.appendChild(dom) dom.click() document.body.removeChild(dom) window.URL.revokeObjectURL(url) console.log('下载成功:', res) this.$message.success('文件下载成功') } catch (error) { console.error('下载失败:', error) this.$message.error('下载失败,请稍后重试') } }, 这是前台对于导出excel的设置 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setCharacterEncoding("UTF-8"); // 使用 URLEncoder 对文件名进行编码,确保兼容性 String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); response.addHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls"); response.setHeader("Content-Disposition", "attachment; filename=\"report.xls\""); // 强制下载,文件名带扩展名 response.setHeader("X-Content-Type-Options", "nosniff"); // 防止 MIME 嗅探 // 或者兼容旧浏览器(同时提供 filename 和 filename*) // response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xlsx\"; filename*=UTF-8''" + encodedFileName + ".xlsx"); ServletOutputStream out = response.getOutputStream(); book.write(out); out.flush(); out.close();这是java后台对于导出excel的设置,为什么能够出现在谷歌浏览器导出的excel文件未受保护,火狐浏览器导出的excel文件受保护,我不像文件受保护需要怎么配置,是配置前台还是配置后台
最新发布
07-23
结合这篇文档,详细说明一下如何自定义DataStream:Custom DataStream ObjectNet provides the facility to send and receive simple and complex structured over-network ( see DataStream ). The main idea of DataStream is to write and read data without the need to write on each place, you can use some DataStream and encapsulate how much data you need. To implement your own DataStream you can check the API document on NetworkEntity class. The following piece of code example how to implement your own DataStream : public class DataToSync { public Vector3 positionValue; public Color color; public DataToSync(Vector3 position, Color color) { this.positionValue = position; this.color = color; } } public class DataStreamExample : DataHandler<Vector3> { public override int Write(DataToSync data, ref byte[] buffer, ref int offset) { int result = base.Write(data.positionValue, ref buffer, ref offset, typeof(Vector3)); result += base.Write(data.color, ref buffer, ref offset, typeof(Color)); return result; } public override DataToSync Read(byte[] buffer, ref int offset) { return new DataToSync(this.Read<Vector3>(buffer, ref offset), this.Read<Color>(buffer, ref offset)); } } After your data stream is created you need to register into stream factory to be visible to ObjectNet engine. DataStream.RegisterGlobalStream<DataToSync, DataStreamExample>(); This code tells to ObjectNet that every time that someone try to send or receive a "DataToSync" object, the "DataStreamExample" must be used.
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值