开发者

create style class in javascript

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜