如何获得当前页面样式表的字符串? [英] How do I get my current page stylesheet as a string?
本文介绍了如何获得当前页面样式表的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我当前的页面如下:
Let's say my current page looks like:
<html>
<head>
<style>
/* I want to get all this as a string.. AS IS */
</style>
</head>
<body>
<script>
function getEntireStyleAsString()
{
var str = "";
/// .... what should be in here?
return str;
}
</script>
</body>
</html>
我想要一个简单的函数,以字符串形式返回页面的整个样式.使用jquery很好.我已经研究了一段时间了,却找不到答案.
I'd like a simple function that returns my entire style of my page as a string. Using jquery is fine. I've been researching this for awhile and can't find the answer.
推荐答案
如果只希望页面上的第一个样式表,则可以使用以下内容:
If you just want the first stylesheet on the page you can use the following:
var ele = document.getElementsByTagName('style')[0].innerHTML;
但是,这只会在第一个样式标签中获得代码.
However this will only get the code within that first style tag.
这篇关于如何获得当前页面样式表的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文