开发者

Simple String and variable problem using jQuery

开发者 https://www.devze.com 2022-12-08 12:37 出处:网络
I\'m trying to add my var to this string: var liPad = 20; $(this).css({\'width\' : width , \'height\' : height, \'padding\' : \"\'0开发者_如何学Cpx\' + liPad + \'px\'\"});

I'm trying to add my var to this string:

var liPad = 20;

$(this).css({'width' : width , 'height' : height, 'padding' : "'0开发者_如何学Cpx' + liPad + 'px'"});

To make it work like this:

$(this).css({'width' : width , 'height' : height, 'padding' : '0 20px'});

Can't figure out how to make it work.

Any help would be appreciated.


This should work:

$(this).css({
    'width': width,
    'height': height,
    'padding': '0 ' + liPad + 'px'
});


I think the issue is that you needed a space where the yyyyyyy is. it was 0px20px

padding' : "'0pxyyyyyyy' + liPad + 'px'"});

The following should work:

var liPad = 20;
$(this).css({'width' : width , 'height' : height, 'padding' : "'0px ' + liPad + 'px'"});
0

精彩评论

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