gpt4 book ai didi

jquery - jQuery 中的混合字符串和变量

转载 作者:行者123 更新时间:2023-12-01 03:12:16 25 4
gpt4 key购买 nike

我在使用此代码时遇到问题

  output.html('<img  width="200" src="uploads/'+response.responseText+'" height="300" >');

它输出:

   <img width="200" height="300" 1269050260.png""="" src="uploads/">

应该是:

   <img width="200" height="300"  src="uploads/1269050260.png">

我尝试了很多方法,例如:

 output.html('<img  width="200" src="uploads/'+response.responseText+'" height="300" >');
output.html('<img width="200" src="uploads/"'+response.responseText+'" height="300" >');
.....

但是当我尝试这个时:

  output.html("<img width='200' src='uploads/"+response.responseText+" height='300' >");

它给出

  <img width="200" 300'="" src="uploads/"1074374482.png" height=">

这也是错误的。

编辑

当我尝试下面的建议时:

   output.html("<img width='200' src='uploads/"+response.responseText+"' height='300' >");

我得到了这个,这也是错误的。

  <img width="200" height="300" src="uploads/"977165688.png"">

当我尝试时:

    output.html("<img width='200' src='uploads/977165688.png' height='300' >"); // this works

最佳答案

最好直接转义“,而不是尝试使用这样的引用规则。试试这个:

output.html("<img  style=\" width: 200px; height: 300px; \" src=\"uploads/" + response.responseText + "\">");

Fiddle

如果这不起作用,那么您就会遇到其他问题。

编辑:

此外,<img> 的宽度和高度属性已被弃用。标签。不要使用它们。请改用 CSS。示例已更新

关于jquery - jQuery 中的混合字符串和变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25495718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com