从元素获取CSS,放入JSON数组,更改元素,恢复元素与存储的CSS数组 [英] Get CSS from element, put in JSON-Array, change element, restore element with stored CSS array

查看:150
本文介绍了从元素获取CSS,放入JSON数组,更改元素,恢复元素与存储的CSS数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想从一个特定的元素,把它放在JSON数组,改变元素周围,稍后从存储的数组中恢复元素的CSS。

So I want to get the css from a particular Element, put it in JSON-array, change element around, later restore the css of the element from the stored Array.

我试过:

var currentCSS = $(this).css;

输出结果如下:

function (a,c) if(arguments.length....



So that seems it takes the function out of the jQuery, that's not what I want...

我可以遍历想要的单独的参数,但应该更好的方法...

I could iterate through the wanted individual arguments, but there should be a better way...

然后,我将尝试类似的:

Then later offcourse I'd try something like:

$(this).css(currentCSS);

优雅的解决方案...

But there might be no elegant solution to doing this...

推荐答案

如果你所有的是内联样式而不是所有的样式属性:

If all you are after is inline style as opposed to all of the style properties:

var $el=$(elem)
var style=$el.attr('style');
$el.removeAttr('style');


/* put style back*/

$el.attr('style',style);

类似地,在操作它之后,删除代码所做的任何内联调整... removed style 属性应该放回到应用的任何原始css

Similarly after you have manipulated it, removing any inline adjustments that your code makes ... removing style attribute should put it back to whatever original css was applied

这篇关于从元素获取CSS,放入JSON数组,更改元素,恢复元素与存储的CSS数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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