Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery的简单字符串和变量问题_Javascript_String Concatenation - Fatal编程技术网

Javascript 使用jQuery的简单字符串和变量问题

Javascript 使用jQuery的简单字符串和变量问题,javascript,string-concatenation,Javascript,String Concatenation,我正在尝试将我的变量添加到此字符串: var liPad = 20; $(this).css({'width' : width , 'height' : height, 'padding' : "'0px' + liPad + 'px'"}); 要使其像这样工作: $(this).css({'width' : width , 'height' : height, 'padding' : '0 20px'}); 我不知道该怎么做 任何帮助都将不胜感激。这应该可以: $(this).css({

我正在尝试将我的变量添加到此字符串:

var liPad = 20;

$(this).css({'width' : width , 'height' : height, 'padding' : "'0px' + liPad + 'px'"});
要使其像这样工作:

$(this).css({'width' : width , 'height' : height, 'padding' : '0 20px'});
我不知道该怎么做

任何帮助都将不胜感激。

这应该可以:

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

我认为问题在于,您需要一个yyyyyy所在的空间。它是0px20px

填充“:”'0pxyyyyyyy'+liPad+'px'})

以下方面应起作用:

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