国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

超清晰的document對(duì)象詳解

2019-11-21 02:15:35
字體:
供稿:網(wǎng)友
document 文擋對(duì)象 - JavaScript腳本語言描述
---------------------------------------------------------------------
注:頁面上元素name屬性和JavaScript引用的名稱必須一致包括大小寫
   否則會(huì)提示你一個(gè)錯(cuò)誤信息 "引用的元素為空或者不是對(duì)象"
---------------------------------------------------------------------

對(duì)象屬性
document.title             //設(shè)置文檔標(biāo)題等價(jià)于HTML的<title>標(biāo)簽
document.bgColor           //設(shè)置頁面背景色
document.fgColor           //設(shè)置前景色(文本顏色)
document.linkColor         //未點(diǎn)擊過的鏈接顏色
document.alinkColor        //激活鏈接(焦點(diǎn)在此鏈接上)的顏色
document.vlinkColor        //已點(diǎn)擊過的鏈接顏色
document.URL               //設(shè)置URL屬性從而在同一窗口打開另一網(wǎng)頁
document.fileCreatedDate   //文件建立日期,只讀屬性
document.fileModifiedDate  //文件修改日期,只讀屬性
document.fileSize          //文件大小,只讀屬性
document.cookie            //設(shè)置和讀出cookie
document.charset           //設(shè)置字符集 簡體中文:gb2312
---------------------------------------------------------------------
對(duì)象方法
document.write()                  //動(dòng)態(tài)向頁面寫入內(nèi)容
document.createElement(Tag)       //創(chuàng)建一個(gè)html標(biāo)簽對(duì)象
document.getElementById(ID)       //獲得指定ID值的對(duì)象
document.getElementsByName(Name)  //獲得指定Name值的對(duì)象
---------------------------------------------------------------------

images集合(頁面中的圖象)

a)通過集合引用
document.images             //對(duì)應(yīng)頁面上的<img>標(biāo)簽
document.images.length      //對(duì)應(yīng)頁面上<img>標(biāo)簽的個(gè)數(shù)
document.images[0]          //第1個(gè)<img>標(biāo)簽           
document.images[i]          //第i-1個(gè)<img>標(biāo)簽

b)通過nane屬性直接引用
<img name="oImage">
document.images.oImage      //document.images.name屬性

c)引用圖片的src屬性
document.images.oImage.src  //document.images.name屬性.src

d)創(chuàng)建一個(gè)圖象
var oImage
oImage = new Image()
document.images.oImage.src="/1.jpg"
同時(shí)在頁面上建立一個(gè)<img>標(biāo)簽與之對(duì)應(yīng)就可以顯示

<html>
<img name=oImage>
<script language="javascript">
   var oImage
   oImage = new Image()
   document.images.oImage.src="/1.jpg"
</script>
</html>

----------------------------------------------------------------------

forms集合(頁面中的表單)

a)通過集合引用
document.forms                 //對(duì)應(yīng)頁面上的<form>標(biāo)簽
document.forms.length          //對(duì)應(yīng)頁面上<form>標(biāo)簽的個(gè)數(shù)
document.forms[0]              //第1個(gè)<form>標(biāo)簽
document.forms[i]              //第i-1個(gè)<form>標(biāo)簽
document.forms[i].length       //第i-1個(gè)<form>中的控件數(shù)
document.forms[i].elements[j]  //第i-1個(gè)<form>中第j-1個(gè)控件

b)通過標(biāo)簽name屬性直接引用
<form name="Myform"><input name="myctrl"></form>
document.Myform.myctrl         //document.表單名.控件名

-----------------------------------------------------------------------
<html>
<!--Text控件相關(guān)Script-->
<form name="Myform">
<input type="text" name="oText">
<input type="password" name="oPswd">
<form>
<script language="javascript">
//獲取文本密碼框的值
document.write(document.Myform.oText.value)
document.write(document.Myform.oPswd.value)
</script>
</html>
-----------------------------------------------------------------------
<html>
<!--Select控件相關(guān)Script-->
<form name="Myform">
<select name="oSelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>

<script language="javascript">
   //遍歷select控件的option項(xiàng)
   var length
   length=document.Myform.oSelect.length
   for(i=0;i<length;i++)
   document.write(document.Myform.oSelect[i].value)
</script>

<script language="javascript">
   //遍歷option項(xiàng)并且判斷某個(gè)option是否被選中
   for(i=0;i<document.Myform.oSelect.length;i++){
   if(document.Myform.oSelect[i].selected!=true)
   document.write(document.Myform.oSelect[i].value)
   else
   document.write("<font color=red>"+document.Myform.oSelect[i].value+"</font>")   
   }
</script>

<script language="javascript">
   //根據(jù)SelectedIndex打印出選中的option
   //(0到document.Myform.oSelect.length-1)
   i=document.Myform.oSelect.selectedIndex
   document.write(document.Myform.oSelect[i].value)
</script>

<script language="javascript">
   //動(dòng)態(tài)增加select控件的option項(xiàng)
   var oOption = document.createElement("OPTION");
   oOption.text="4";
   oOption.value="4";
   document.Myform.oSelect.add(oOption);
</script>
<html>
-----------------------------------------------------------------------
<Div id="oDiv">Text</Div>
document.all.oDiv                       //引用圖層oDiv
document.all.oDiv.style                 
document.all.oDiv.style.display=""      //圖層設(shè)置為可視
document.all.oDiv.style.display="none"  //圖層設(shè)置為隱藏
/*document.all表示document中所有對(duì)象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋中市| 乐山市| 准格尔旗| 青浦区| 周宁县| 郧西县| 扎鲁特旗| 织金县| 大同市| 东平县| 益阳市| 长海县| 翁牛特旗| 工布江达县| 昌都县| 伊宁市| 昭苏县| 南陵县| 龙江县| 宝兴县| 肥西县| 左云县| 西贡区| 池州市| 永福县| 叶城县| 东台市| 中牟县| 张家界市| 金华市| 新余市| 西平县| 抚州市| 苗栗县| 内江市| 连南| 同仁县| 井冈山市| 镇坪县| 宁明县| 罗江县|