首页 > web前端 > js教程 > 正文

超清晰的document对象详解_基础知识

php中文网
发布: 2016-05-16 19:18:43
原创
842人浏览过

document 文挡对象 - JavaScript脚本语言描述
---------------------------------------------------------------------
注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写
   否则会提示你一个错误信息 "引用的元素为空或者不是对象"
---------------------------------------------------------------------

对象属性
document.title             //设置文档标题等价于HTML的

Nanonets
Nanonets

基于AI的自学习OCR文档处理,自动捕获文档数据

Nanonets 258
查看详情 Nanonets
标签 <br>document.bgColor           //设置页面背景色 <br>document.fgColor           //设置前景色(文本颜色) <br>document.linkColor         //未点击过的链接颜色 <br>document.alinkColor        //激活链接(焦点在此链接上)的颜色 <br>document.vlinkColor        //已点击过的链接颜色 <br>document.URL               //设置URL属性从而在同一窗口打开另一网页 <br>document.fileCreatedDate   //文件建立日期,只读属性 <br>document.fileModifiedDate  //文件修改日期,只读属性 <br>document.fileSize          //文件大小,只读属性 <br>document.cookie            //设置和读出cookie <br>document.charset           //设置字符集 简体中文:gb2312 <br>--------------------------------------------------------------------- <br>对象方法 <br>document.write()                  //动态向页面写入内容 <br>document.createElement(Tag)       //创建一个html标签对象 <br>document.getElementById(ID)       //获得指定ID值的对象 <br>document.getElementsByName(Name)  //获得指定Name值的对象 <br>--------------------------------------------------------------------- <br><br>images集合(页面中的图象) <br><br>a)通过集合引用 <br>document.images             //对应页面上的<img alt="超清晰的document对象详解_基础知识" >标签 <br>document.images.length      //对应页面上<img alt="超清晰的document对象详解_基础知识" >标签的个数 <br>document.images[0]          //第1个<img alt="超清晰的document对象详解_基础知识" >标签            <br>document.images[i]          //第i-1个<img alt="超清晰的document对象详解_基础知识" >标签 <br><br>b)通过nane属性直接引用 <br><img alt="超清晰的document对象详解_基础知识" ><br>document.images.oImage      //document.images.name属性 <br><br>c)引用图片的src属性 <br>document.images.oImage.src  //document.images.name属性.src <br><br>d)创建一个图象 <br>var oImage <br>oImage = new Image() <br>document.images.oImage.src="/1.jpg" <br>同时在页面上建立一个<img alt="超清晰的document对象详解_基础知识" >标签与之对应就可以显示 <br><br><br><img alt="超清晰的document对象详解_基础知识" ><br><script> <BR> var oImage <BR> oImage = new Image() <BR> document.images.oImage.src="/1.jpg" <BR></script><br><br><br>---------------------------------------------------------------------- <br><br>forms集合(页面中的表单) <br><br>a)通过集合引用 <br>document.forms                 //对应页面上的<form>标签 <br>document.forms.length          //对应页面上</form> <form>标签的个数 <br>document.forms[0]              //第1个</form> <form>标签 <br>document.forms[i]              //第i-1个</form> <form>标签 <br>document.forms[i].length       //第i-1个</form> <form>中的控件数 <br>document.forms[i].elements[j]  //第i-1个</form> <form>中第j-1个控件 <br><br>b)通过标签name属性直接引用 <br> </form> <form><input></form> <br>document.Myform.myctrl         //document.表单名.控件名 <br><br>----------------------------------------------------------------------- <br><br><!--Text控件相关Script--><br><form> <br><input><br><input><br> </form> <form> <br><script> <BR>//获取文本密码框的值 <BR>document.write(document.Myform.oText.value) <BR>document.write(document.Myform.oPswd.value) <BR></script><br><br>----------------------------------------------------------------------- <br><br><!--Select控件相关Script--><br> </form> <form> <br><select><br><option>1</option> <br><option>2</option> <br><option>3</option> <br></select><br> </form> <br><br><script> <BR> //遍历select控件的option项 <BR> var length <BR> length=document.Myform.oSelect.length <BR> for(i=0;i<length;i++) <BR> document.write(document.Myform.oSelect[i].value) <BR></script><br><br><script> <BR> //遍历option项并且判断某个option是否被选中 <BR> for(i=0;i<document.Myform.oSelect.length;i++){ <BR> if(document.Myform.oSelect[i].selected!=true) <BR> document.write(document.Myform.oSelect[i].value) <BR> else <BR> document.write("<font color=red>"+document.Myform.oSelect[i].value+"") <BR> } <BR></script><br><br><script> <BR> //根据SelectedIndex打印出选中的option <BR> //(0到document.Myform.oSelect.length-1) <BR> i=document.Myform.oSelect.selectedIndex <BR> document.write(document.Myform.oSelect[i].value) <BR></script><br><br><script> <BR> //动态增加select控件的option项 <BR> var oOption = document.createElement("OPTION"); <BR> oOption.text="4"; <BR> oOption.value="4"; <BR> document.Myform.oSelect.add(oOption); <BR></script><br><br>----------------------------------------------------------------------- <br><div>Text</div> <br>document.all.oDiv                       //引用图层oDiv <br>document.all.oDiv.style                  <br>document.all.oDiv.style.display=""      //图层设置为可视 <br>document.all.oDiv.style.display="none"  //图层设置为隐藏 <br>/*document.all表示document中所有对象的集合 <br>只有ie支持此属性,因此也用来判断浏览器的种类*/ <br><br>
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号