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

首頁(yè) > 開發(fā) > CSS > 正文

針對(duì)不同瀏覽器獲取到css文件里相關(guān)屬性的兩種方法

2024-07-11 08:39:35
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

先看個(gè)例子


<div style=”font-size:100px;”>1111</div>
<p>2222</p>
<style>*{font-size:50px;}</style>

此時(shí) 如果用 document.querySelector("p").style.fontSize 是獲取不到50px 值的 而 document.querySelector("div").style.fontSize 返回的是100

因此可以得知document.querySelector(elements).style 只針對(duì)與標(biāo)簽上的屬性,如果在外部css 文件中的屬性如何獲取?

這里介紹兩個(gè)方法針對(duì)不同瀏覽器

1、 obj.currentStyle

2、window.getComputedStyle


function getCurCss(id,porp){
var obj = document.getElementById(id);
if (obj.currentStyle) {
return obj.currentStyle[prop];
} else if (window.getComputedStyle) {
propprop = prop.replace(/([A-Z])/g, “-$1”);
propprop = prop.toLowerCase();
return document.defaultView.getComputedStyle(obj, null)[prop];
}
return null;
}
getCurCss(id,”fontSize”);

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙门县| 新干县| 德钦县| 衡水市| 玉田县| 化隆| 洪江市| 博湖县| 兰溪市| 曲沃县| 永仁县| 罗城| 城固县| 延安市| 高陵县| 甘孜| 石阡县| 鄢陵县| 西青区| 临高县| 滦南县| 泗洪县| 江川县| 永吉县| 常州市| 登封市| 册亨县| 织金县| 绵阳市| 视频| 平谷区| 珲春市| 舞阳县| 新河县| 晴隆县| 荥阳市| 酒泉市| 金山区| 六盘水市| 印江| 达拉特旗|