开发者

create style class in javascript

开发者 https://www.devze.com 2022-12-08 10:06 出处:网络
i want to crate style class in java script tags and class will be like this #file-ok { background-image: url(+json.get(\'filename\')+);

i want to crate style class in java script tags

and class will be like this

     #file-ok {
        background-image: url(+   json.get('filename')   +);
     }

actually json.get开发者_如何学Go('filename') will be name of file for background and will return from php file.

is this possible...?


You can get your image filename and then set it as the background of the #file-ok element when the Ajax request ends:

$(function () {
  $.get("file.php", function(data){
    $('#file-ok').css('backgroundImage', 'url(' + data.filename + ')');
  });
});


The simplest way is to apply an inline style, but this is no good if you need to apply this to multiple elements then look at using setProperty() on a CSSRule.

You can find a great write up here - http://www.quirksmode.org/dom/changess.html

0

精彩评论

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

关注公众号