开发者

Copy CSS from one class to another with JQuery?

I would like to make a timepicker similar to the datepicker, conforming to the current UI Theme. Can I copy, or somehow inherit, the CSS properties from datepicker to my timepicker? I do'nt want to copy the behaviour of the class, just the CSS props.

(I've seen other timepickers out there, but I'm not really happy with 开发者_运维百科any of them...)


This is difficult to do as CSS and HTML markup (and javascript code) are very tightly coupled together. Also the CSS requires some images (usually a big one with tens of images - css selects which portion of the big image is to be shown).

In order to inherit the css, you need also to inherit the class names and use the same in your datepicker. The datepicker has dependencies also to the core jquery.ui.css and not just the datepicker.css. So, you need to also take this into account.


You could use jQuery to read all the required values, setting them as variables on the way:

var color = $(this).css("background-color");
var padding = $(this).css("padding");

Etc etc...

Then output them via:

$(this).css({'background-color' : color+'px', 'padding' : padding+'px'});

Does that make sense, it's not really copying the stylesheet, but it is reading the sections are appending them to another element...

Best of luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜