今天分享一些关于js中document常见的一些用法以及含义.
document.title //设置文档的标题与<title>标签意思一样
document.fgColor //设置文本颜色的前景色
document.bgColor //设置页面的背景色
document.linkColor //还没有点击的链接颜色
document.vlinkColor //已经点击过的链接的颜色
document.alinkColor //输在指针在链接上的颜色
document.URL //设置URL属性在同一个窗口中打开新页面
document.fileModifiedDate //文件的修改日期 只读属性
document.fileCreatedDate //文件的建立日期 只读属性
document.fileSize //文件的大小 只读属性
document.cookie //读取与设置js cookie
document.charset //设置字符集
document.images //指定页面上的<img>
document.images.length //对应页面上<img>元素个数
document.images[0] //第1个<img>标签元素
document.images[i] //第i-1个<img>标签元素
<img name="qtoolimg">
document.images.qtoolimg //document.images.name属性
c)引用图片的src属性
代码
document.images.qtoolimg.src //document.images.name属性.src
d)创建一个图象
var qtoolimg
qtoolimg = new Image()
document.images.qtoolimg.src=" "
document.write() //动态的在页面中插入内容
document.getElementById(ID) //获取指定ID值的对象
document.createElement(Tag) //创建一个新的html标签
document.getElementsByName(Name) //查看指定Name值的对象
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个控件
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) //打开新网页
document.getElementById("ID").innerText //动态输出文本
document.getElementById("ID").innerHTML //动态输出HTML
document.getElementById("ID").outerText //同innerText
document.getElementById("ID").outerHTML //同innerHTML
<div id="ccc">xxxx</div>
document.all.ccc //引用图层
document.all.ccc.style.display="" //显示图层
document.all.ccc.style.display="none" //图层隐藏
document.getElementId("ccc") //通过getElementId引用对象
document.getElementId("ccc").style=""
document.getElementId("ccc").display="none"
以上就是
在线工具分享的关于document常见的一些用法整理