不确定如何以正确的方式编写它。我可以让它工作但是当我查看源代码时它看起来像这样
<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%;" ">');
最佳答案
更改为:
foo.append(
$("<img />", {
src: img,
style: "width: 30%; height: 30%"
})
);
通过这种方式更容易避免引号不匹配的错误,并且通常也提高了可读性
关于javascript - 与 jquery 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15323678/