COMMENT 元素 | comment 對象
CUSTOM 元素 | custom 對象
DHTML 對象
代表了在全局樣式表、內嵌樣式和 HTML 標簽屬性中指定的對象格式和樣式。
成員表
屬性 描述 blockDirection 獲取表明塊元素內容的繞排方向的值,是由左至右,還是由右至左。 clipBottom 獲取對象剪裁區(qū)域的底邊坐標。 clipLeft 獲取對象剪裁區(qū)域的左邊坐標。 clipRight 獲取對象剪裁區(qū)域的右邊坐標。 clipTop 獲取對象剪裁區(qū)域的頂邊坐標。 onOffBehavior 獲取表明指定的 Microsoft® DirectAnimation® 行為是否正在運行的對象。
方法 描述 getAttribute 獲取指定標簽屬性的值。 getExpression 獲取給定屬性的表達式。 setAttribute 設置指定標簽屬性的值。 setExpression 設置指定對象的表達式。
注釋
currentStyle 對象返回了元素上的樣式表,但是 style 對象只返回通過 STYLE 標簽屬性應用到元素的內嵌樣式。因此,通過 currentStyle 對象獲取的樣式值可能與通過 style 對象獲取的樣式值不同。例如,如果段落的 color 屬性值通過鏈接或嵌入樣式表設置為紅色( red ),而不是內嵌的話,對象.currentStyle.color 將返回正確的顏色,而對象 style.color 不能返回值。但是,如果用戶指定了 <P STYLE="color:'red'">,currentStyle 和 STYLE 對象都將返回值 red。
currentStyle 對象反映了樣式表中的樣式優(yōu)先順序。在 HTML 中此順序為:
- 內嵌樣式
- 樣式表規(guī)則
- HTML 標簽屬性
- HTML 標簽的內部定義
從而,currentStyle 對象將為 bold 標簽返回 fontWeight 值 normal,若在樣式表中為此標簽指定了 normal。
currentStyle 返回反映頁面所應用的樣式設置的值,但可能并不反映獲取值時渲染所采用的值。例如,樣式值設置為 "color:red; display:none" 的對象,將返回 currentStyle.color 為 red,盡管該對象并不在頁面上渲染。也就是說,currentStyle 對象并不受渲染與否的綁定。在下面示例區(qū)的第三個例子演示了此行為。禁用的樣式表也不影響 currentStyle 值。
返回值的單位與設置對象時的單位相同。例如,若對象的顏色是以內嵌 STYLE="color:'green'" 的格式設置的,那么 object.currentStyle.color 將返回 green 而不是 #00FF00 (與綠色相等的紅綠藍十六進制值)。但是,當 currentStyle 對象返回對象值的時候出現在作者所設置的對象值中的大寫和多余的空白將被去掉。
currentStyle 對象支持用戶自定義的樣式規(guī)則屬性。請參看示例區(qū)的第二個例子。
currentStyle 對象是異步的。這意味著樣式不可能被設置后馬上就能查詢,而是返回舊值。因此,對于含有 addImport 這樣方法的想要獲得所期待的 currentStyle 行為的腳本,該腳本需要包含一個調用方法的函數和一個檢查 currentStyle 的函數。對于需要在頁面裝載的時候檢查當前屬性的腳本,腳本必須等到 body 元素裝入且頁面被選然后,否則 currentStyle 的值可能不反映所顯示的情況。
此對象在 Microsoft® Internet Explorer 5 的腳本中可用。
示例
下面的例子使用 currentStyle 對象將文本顏色設置為棕色。如果你單擊著色區(qū)域并且背景顏色與文本顏色相同,checkColor 函數就會更改背景顏色,以方便閱讀文本。否則,該函數不做任何操作。
這個例子僅當主體和文本顏色同時使用顏色名稱或 RGB 十六進制值時可用,混合使用時無效。
<SCRIPT> function checkColor(oObj) { if (oObj.currentStyle.backgroundColor == 'brown') { oObj.style.backgroundColor = 'white'; } else : } </SCRIPT> </HEAD> : <P STYLE="background-color: 'brown'" onclick="checkColor(this)">這個例子使用 currentStyle 對象獲取創(chuàng)建于樣式規(guī)則的用戶自定義屬性。alert 返回值 myvalue。
<STYLE> P { myproperty:myvalue } </STYLE> <BODY> <P ID=oPrgrph> : <SCRIPT> alert(oPrgrph.currentStyle.myproperty) </SCRIPT>這個例子由 currentStyle 對象返回的 td 對象寬度是其層疊寬度值而不是屏幕上渲染的寬度值。
<BODY ID=oBdy> : <TABLE BORDER> <TR><TD WIDTH=1100 ID=oTblD>text</TD></TR> </TABLE> : <SCRIPT> alert("TD 對象 currentStyle.width 為 " + oTblD.currentStyle.width + ".\n" + "窗口的寬度為 " + oBdy.clientWidth + "px.\n屏幕的寬度為 " + screen.width + "px." ) </SCRIPT>
標準信息
沒有應用于此對象的公共標準。
應用到
a, acronym, address, applet, b, bdo, big, blockQuote, body, br, button, caption, center, cite, code, col, colGroup, custom, dd, del, dfn, dir, div, dl, dt, em, embed, fieldSet, font, form, hn, html, i, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, ins, isIndex, kbd, label, legend, li, listing, marquee, menu, noBr, object, ol, option, p, plainText, pre, q, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tr, tt, u, ul, var, wbr, xmp
參看
style