Javascript 与jquery的连接

Javascript 与jquery的连接,javascript,jquery,string,concatenation,Javascript,Jquery,String,Concatenation,不知道该如何用正确的方式写。我可以让它工作,但当我查看源代码时,它看起来是这样的 <img "="" "style="width:30%; height:30%;" src="correctsource"></img> 正如您在图像标签的旁边看到的,它们是两个额外的引号&一个等号 这是我的密码 var img = $(this).attr('src'); //grab the visible div and the div with class editit

不知道该如何用正确的方式写。我可以让它工作,但当我查看源代码时,它看起来是这样的

<img "="" "style="width:30%; height:30%;"   src="correctsource"></img>

正如您在图像标签的旁边看到的,它们是两个额外的引号&一个等号

这是我的密码

var img = $(this).attr('src');
  //grab the visible div and the div with class edititable within it and append image
  $(".open:visible").find('.edititable').append('<img src="' + img + '" "style="width:30%; height:30%;" ">');
var img=$(this.attr('src');
//抓取可见div和其中包含可编辑类的div,并附加图像
$(“.open:visible”).find(“.editable”).append(“”);

试试这个,字符串中的双引号太多了

$(".open:visible").find('.edititable').append('<img src="' + img + '" style="width:30%; height:30%;">');
$(“.open:visible”).find(“.editable”).append(“”);

试试这个,字符串中的双引号太多了

$(".open:visible").find('.edititable').append('<img src="' + img + '" style="width:30%; height:30%;">');
$(“.open:visible”).find(“.editable”).append(“”);

删除最后一个双引号,它就会工作。您添加了一个额外的双引号

那是我写的

 .................height:30%;">');

删除最后的双引号,然后它就会工作。您添加了一个额外的

那是我写的

 .................height:30%;">');
改为:

foo.append(
    $("<img />", { 
        src: img, 
        style: "width: 30%; height: 30%" 
    })
);
foo.append(
$("
这样更容易避免引号不匹配的错误,并且通常也提高了可读性

更改为:

foo.append(
    $("<img />", { 
        src: img, 
        style: "width: 30%; height: 30%" 
    })
);
foo.append(
$("

这样可以更容易地避免引号不匹配的错误,并且通常也可以提高可读性。

关闭,您的字符串只是格式不正确。您在style.Tech前面有一个额外的“字体”。您将其编写为

$(".open:visible").find('.edititable').text('<img src="' + img + ' " style="width:30%; height:30%;" ">');
$(“.open:visible”).find(“.editable”).text(“”);

相关提琴:

关闭,您的字符串只是格式不正确。您的样式前面有一个额外的“字体”。您将其编写为

$(".open:visible").find('.edititable').text('<img src="' + img + ' " style="width:30%; height:30%;" ">');
$(“.open:visible”).find(“.editable”).text(“”);

相关提琴:

img末尾的额外引号
tag
img
tag+1结尾的额外引号,但请注意,此方法仅适用于+1,但请注意,此方法仅适用于