
例如,我想在当前页面中获取字体大小的样式值

在IE浏览器中,可以使用element.currentStyle.specific属性方法获取特定值.

但是js浏览器兼容问题,currentStyle在360和FF中将无效. 这时,获取getComputedStyle(元素,伪类名称). 使用属性方法. 如果伪类名称不存在js浏览器兼容问题,请输入null.

兼容性描述如下:

var target = document.getElementByID("a");
var tag_fontsize = null;
if(target.currentStyle)//IE
{
tag_fontsize = target.currentStyle.fontSize;
}
else//360 and FireFox
{
tag_fontsize = getComputedStyle(target, null).fontSize;
}
/**获取屏幕的宽度*/
var winWidth = 0;//屏幕的宽px
if(typeof(window.innerWidth) == "number")//360和火狐浏览器
{
winWidth = window.innerWidth;
}
else if ((document.body) && (document.body.clientWidth))//IE浏览器
{
winWidth = document.body.clientWidth;
}
window.onresize函数仅在Internet Explorer中有效,并且在360和FF中均无效,因此最明智的解决方案是使用jQuery: $(window).resize(function(){blabal ... ...});而不是JS中的window.onresize = fucntion(blabla ......);
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-193046-1.html
#宋茜4walls#
封口费给的不少