JS中document對象的一些重要屬性
- forms數組對象:代碼網頁中所有form標簽的集合
- anchors數組對象:指定了網頁中所有指定了name或id屬性的<a>標簽的集合,但不包括指定了href標簽的集合
- links數組對象 指所有指定了href屬性的<a>標簽的集合
- images數組對象:指定了文檔中所有的<img>標簽的集合
- scripts數組對象:代表了文檔中所有的<script>標簽的集合
- applets數組對象:代表了文檔中所有的<applets>標簽的集合
- all數組對象:代表所有文檔中所有的標簽
- styleSheets數組對象:文檔中所有引入的樣式表的集合
- body對象:代表文檔當中套在<body>標簽對裏面的HTML子元素,可以作為body對象的屬性來引用
- title對象:代表文檔中的<title>標簽對,用來設置和引用網頁標簽欄上的內容
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應頁面上的form標簽
document.forms.length //對應頁面上/formform標簽的個數
document.forms[0] //第1個form標簽
document.forms[i] //第i-1個fform標簽
document.forms[i].length //第i-1個orm中的控件數
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 //對應第i個form的name屬性
document.forms[i].action //對應第i個form的action屬性
document.forms[i].encoding //對應第i個form的encoding屬性
document.forms[i].target //對應第i個form的target屬性
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” src="1.jpg">
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 /標簽與之對應就可以顯示
JS中document對象的一些重要屬性