设置'src'img标记使用主干模板动态创建

Setting 'src' of img tag dynamically using backbone templating

本文关键字:创建 动态 img src 设置      更新时间:2023-12-11

我试图通过骨干模板动态设置img标签的src,但/会自动附加,而img没有加载。模板的部分看起来像-

<script type="text/template" id="home">
.......
<% var d=names[0].get("image_link")+".jpg" 
//d=d.substring(0 , d.length-1); tried to cut down last char
%>
<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all"  width="100%" height="auto" src=<%=d%> /> 
.......
</script>

输出-

<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all"  width="100%" height="auto" src="image1.jpg/" />

我不知道如何在img src中排除那个/。有什么建议吗。

这个斜杠实际上就在代码中。由于属性值周围没有任何引号,/>中的/将成为该值的一部分。

添加引号:

<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all"  width="100%" height="auto" src="<%=d%>" />