如何在引用的html、javascript中解析背景图像url中的字符串?
从控制器到symfony2中的index.html.twig的ajax调用(图像名称:Logo,JGP-lille70720150924032031.jpg)中获取图像名称作为响应后,将图像放入javascript表变量,如下所示 数据[索引].Interestlogo=图像名称如何在引用的html、javascript中解析背景图像url中的字符串?,javascript,html,css,ajax,twig,Javascript,Html,Css,Ajax,Twig,从控制器到symfony2中的index.html.twig的ajax调用(图像名称:Logo,JGP-lille70720150924032031.jpg)中获取图像名称作为响应后,将图像放入javascript表变量,如下所示 数据[索引].Interestlogo=图像名称 table=""; table += "<div class='imgparam th' style='background-image: url({{basepath}}/uploads/Int
table="";
table += "<div class='imgparam th' style='background-image: url({{basepath}}/uploads/Interests/"+data[index].Idinterestmaster+"/thumbnails/"+data[index].Interestlogo+")'></div>";
$("#results").append(table);
table=”“;
表+=”;
$(“#结果”)。追加(表格);
在这里,所有正常的图像名称都可以正常工作。
如果图像名称=徽标,JGP-lille70720150924032031.jpg则图像不显示
在这里,我需要在下面加上双引号
背景图片:url(“路径应位于此处”)
我所得到的是如下所示
背景图片:url(路径应位于此处)//这里没有双引号
请告诉我如何使用双引号。如果您正在动态创建URI,则必须确保它们是websafe URI 它们不能包含空格。但这就是为什么当你看这个问题的标题时,它有很多破折号
/questions/32783366/how-to-parse-a-string-in-background-image-url-in-quoted-html-javascript
我建议通过URL编码器运行代码
我希望这有助于如果您要动态创建URI,您必须确保它们是websafe URI 它们不能包含空格。但这就是为什么当你看这个问题的标题时,它有很多破折号
/questions/32783366/how-to-parse-a-string-in-background-image-url-in-quoted-html-javascript
我建议通过URL编码器运行代码
我希望这对我有所帮助,经过大量的研究,最后我很高兴我得到了解决方案。我已经分离了url路径并将其放入var urlpath中。 对于urlpath,通过在应答代码中使用斜杠应用引号 最后,带引号的url已替换为背景图片url
var urlpath="{{basepath}}/uploads/Interests/"+data[index].Idinterestmaster+"/thumbnails/"+data[index].Interestlogo;
var withdoublequotes="\""+urlpath+"\"";
table += "<div class='imgparam th' style='background-image: url("+withdoublequotes+")'></div>";
var urlpath=“{{basepath}}/uploads/Interests/”+数据[index].iditeresmaster+“/thumbnails/”+数据[index].Interestlogo;
var with doublequotes=“\”“+urlpath+”\”;
表+=”;
经过大量的研究,最后我很高兴我得到了解决方案。我将url路径分离并放入var urlpath中。
对于urlpath,通过在应答代码中使用斜杠应用引号
最后,带引号的url已替换为背景图片url
var urlpath="{{basepath}}/uploads/Interests/"+data[index].Idinterestmaster+"/thumbnails/"+data[index].Interestlogo;
var withdoublequotes="\""+urlpath+"\"";
table += "<div class='imgparam th' style='background-image: url("+withdoublequotes+")'></div>";
var urlpath=“{{basepath}}/uploads/Interests/”+数据[index].iditeresmaster+“/thumbnails/”+数据[index].Interestlogo;
var with doublequotes=“\”“+urlpath+”\”;
表+=”;