开发者

Jquery multi css using variables

I am having an issue with this jquery css:

Like this it works in all browsers but ie9:

  $(".%id%faderbox").css({
    "background-image": "url("+bgimage+")",
    "padding": "%id=xtrapadding%px",
 开发者_JAVA百科   "height": dooheight,
    "width": doowidth,
    "border": doofaderborder
 });

dooheight and doowidth are variables declared further up the page, and always return ie: 133px

note: the px on the end. note: not encloded like: "133px"

now the issue with ie9 seems to be that it does not like the width and height values without the enclosing qoutes ""

So.. ok i thought, i will just do this for example:

"width": '"' + doowidth + '"',

But this does not work in any browser, even though an alert test clearly shows the value of doowidth now returns: "133px" instead of 133px

hard coding: "width": "133px", works in all browsers including ie 9

I cant understand why it breaks in all browsers with:

"width": '"' + doowidth + '"',


Where does this %id and %id=xtrapadding% nonsense come from?

And there's no use adding quotes to the strings. They're already strings. The quotes are part of the syntax you use to delimit string literals: they are not actually in the strings themselves, so adding them is wrong.

It seems to me that, for some reason and in some cases, doowidth is not being seen as a string. You can force it to be by appending nothingness. Try this:

$(".%id%faderbox").css({
    "background-image": "url("+bgimage+")",
    "padding":          "%id=xtrapadding%px",
    "height":           dooheight + '',
    "width":            doowidth + '',
    "border":           doofaderborder + ''
});


try using single quotes

'"' + doowidth + '"'

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜