Simple String and variable problem using jQuery
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'"});
精彩评论