Maison  >  Article  >  interface Web  >  获取内联和链接中的样式(js代码)_javascript技巧

获取内联和链接中的样式(js代码)_javascript技巧

WBOY
WBOYoriginal
2016-05-16 17:37:181101parcourir
复制代码 代码如下:

var head = document.getElementById( "box" );
// alert( head.style.background )
// alert( head.style.cssFloat || head.style.styleFloat ) // 获取float不一样
// head.style.fontSize = "30px"
head.style.color = "#f00";
// (typeof head.style.cssFloat != "undefined" ) ? head.style.cssFloat = "right" : head.style.styleFloat = "right" 跨浏览器设置float
// var style = ( window.getComputedStyle ? window.getComputedStyle( head,null ) : null ) || head.currentStyle; 跨浏览器获取计算之后的样式
// alert( style.fontSize )
// 这样可以获取到内联和链接
// 因为计算之后的样式会驻留在浏览器的计算样式里面 所以就可以获取得到
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn