如何从CSS文件用jQuery读取 [英] How to read from CSS files with jQuery

查看:116
本文介绍了如何从CSS文件用jQuery读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个包含jQuery的HTML页面。

Ok, I have a HTML page with jQuery included.

我有一个CSS文件,所有样式从外部CSS文件...不是内联样式...

I have a CSS file with a good load of lines in, I would like to read all styles for a given element from the external CSS file... Not the inline styles...

我有以下代码应该工作...):

I have the following code (which looks like it should work...):

var styleProperties= {};
var getCssProperties = ['width', 'margin', 'height']; 

for (c=0;c<=returnStyleProps.length;c++) {
    styleProperties[returnStyleProps[c]] = $('div#container').css(returnStyleProps[c]);
    alert(styleProperties);
}
alert(styleProperties);

但这只是提醒:

"[Object Object]"

] 请...?我真的很困惑,没有什么似乎工作:( [/ edit]

推荐答案

var cs = {};
var elem = $('h1')[0];
for(var s in elem.style)
{
    // console.log(s + typeof(s));
    var v = $(elem).css(s);
    if (v && v != '')
    {
        cs[s] = v;
    }
}

for(var s in cs)
{
    console.log(s + ': ' + cs[s]);
}

在firebug如果你有页面上的h1元素和jQuery使用...
只是一个粗略的想法,但...

please run in firebug if you have h1 element on the page and jQuery is used... just a rough idea though...

这篇关于如何从CSS文件用jQuery读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆