使用Javascript / jQuery从外部样式表获取CSS值 [英] Get a CSS value from external style sheet with Javascript/jQuery
本文介绍了使用Javascript / jQuery从外部样式表获取CSS值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果尚未生成样式引用的元素,是否可以从页面的外部CSS获取值? (元素是动态生成的)。
Is it possible to get a value from the external CSS of a page if the element that the style refers to has not been generated yet? (the element is to be generated dynamically).
我看到的jQuery方法是 $('element')。css ');
,但这依赖于页面上的元素
。是否有一种方法来找出属性设置在CSS而不是计算的样式的元素?
The jQuery method I've seen is $('element').css('property');
, but this relies on element
being on the page. Is there a way of finding out what the property is set to within the CSS rather than the computed style of an element?
我会做一些丑陋的事情像添加
Will I have to do something ugly like add a hidden copy of the element to my page so that I can access its style attributes?
推荐答案
这似乎可以工作:
<style>
p {color: blue}
</style>
$(document).ready(function() {
var $p = $("<p></p>").hide().appendTo("body");
alert($p.css("color"));
$p.remove();
});
这篇关于使用Javascript / jQuery从外部样式表获取CSS值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文