有没有办法获取应用于页面的所有 CSS 规则?目前,我正在使用 jQuery 来执行此操作,但是否有服务器端解决方案?
var style = "";
//grab all styles defined on the page
$("style").each(function () {
style += $(this).html() + "\n";
});
$.ajaxSetup({ async: false });
//grab all styles referenced by stylesheet links on the page
$("[rel=stylesheet]").each(function () {
$.get(this.href, '', function (data) {
style += data + "\n";
});
});
$.ajaxSetup({async: true});
style = "<style type='text/css'>" + style + "</style>";