最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

style、 currentStyle、 runtimeStyle區(qū)別分析

 更新時間:2010年08月01日 16:43:33   作者:  
style、 currentStyle、 runtimeStyle區(qū)別分析,需要的朋友可以參考下。
1、obj.style只能獲得內(nèi)嵌樣式(inline Style)就是寫在Tag里面的,他訪問不到那些鏈接的外部css和在head中用<style>聲明的style。
所以必須認(rèn)識到在那些使用外部Css文件的頁面中,如果用style賦值,如obj.style=“color:red”;顯然效果是正確的,其中的奧秘確是只是在該對象的tag上多添加了一個style屬性,按照由小到大的優(yōu)先級呈現(xiàn)罷了。
2、obj.currentStyle就強大多了,他能夠獲取關(guān)于這個節(jié)點所有位置的style,但是他也按照優(yōu)先級,說穿了就是顯示的是什么他就是指向哪一個style,如下代碼字體優(yōu)先是顯示blue的,那currentStyle.color就是blue,當(dāng)然此時style.color也會是blue。
復(fù)制代碼 代碼如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>testStyle</title>
<style>
.lala{
color:yellow;
}
</style>
</head>
<body>
<div id="tt" style="color:blue;" class="lala">1111</div>
</body>
<script>
alert(document.getElementById("tt").currentStyle.color);
</script>
</html>

若去掉以上<div>中的style為<div id="tt" class="lala">1111</div>,那么currentStyle.color就根據(jù)優(yōu)先級變成了yellow,但是此時style.color為空。
3、runtimeStyle簡單的說就是你可以對一個節(jié)點的樣式賦值,他將成為最高優(yōu)先級的節(jié)點樣式。
如:
復(fù)制代碼 代碼如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
.lala{
color:yellow;
}</style>
</head>
<body>
<div id="tt" style="color:blue;" class="lala">1111</div>
</body>
<script>
document.getElementById("tt").runtimeStyle.color="black";
alert(document.getElementById("tt").currentStyle.color);
alert(document.getElementById("tt").runtimeStyle.color);
alert(document.getElementById("tt").style.color);
</script>
</html>

此時頁面顯示字的顏色是runtimeStyle賦值后的black。但是只有currentStyle.color和runtimeStyle本身能夠取到這個值,style.color取到的依然是tag中的blue。

相關(guān)文章

最新評論

拜城县| 阿合奇县| 关岭| 米泉市| 杨浦区| 临清市| 江津市| 乐山市| 甘肃省| 东乡| 德安县| 潼南县| 宜黄县| 泗洪县| 溧水县| 崇礼县| 苍梧县| 罗定市| 体育| 拉萨市| 崇左市| 手机| 霍邱县| 东源县| 文安县| 镇安县| 仙游县| 革吉县| 定南县| 米林县| 塔河县| 从江县| 屏边| 孟州市| 吴堡县| 姚安县| 仲巴县| 孟津县| 南澳县| 甘孜县| 隆子县|