Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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 JS串联转义斜杠_Javascript_Jquery - Fatal编程技术网

Javascript JS串联转义斜杠

Javascript JS串联转义斜杠,javascript,jquery,Javascript,Jquery,我尝试将url连接为背景图像。我的jquery: Img = "http://something.com"; html = '<div class="Img" style="background:url("' + Img + '") no-repeat"></div>'; 由于您已经在使用jQuery,我建议您使用它来创建div var html = $('<div></div>') .addClass('Img') .css({

我尝试将url连接为背景图像。我的jquery:

Img = "http://something.com";
html = '<div class="Img" style="background:url("' + Img + '") no-repeat"></div>';

由于您已经在使用jQuery,我建议您使用它来创建div

var html = $('<div></div>')
    .addClass('Img')
    .css({
        "background":"url('" + Img + "') no-repeat"
    }); 
var html=$(“”)
.addClass('Img'))
.css({
“背景”:“url(“+Img+”)不重复”
}); 
不过,最直接的解决办法是,您需要正确使用引号

html = '<div class="Img" style="background:url(\'' + Img + '\') no-repeat"></div>';
html=”;
var Img=”http://something.com";
var html='Yahooo';
$(文档).ready(函数(){
$('#a').html(html)
});

html = '<div class="Img" style="background:url(\'' + Img + '\') no-repeat"></div>';