简体   繁体   English

如何创建内部带有img标签的锚标签

[英]How to create an anchor tag with an img tag inside

I'm trying to recreate an element like this: 我正在尝试重新创建一个像这样的元素:

 <a href='https://www.myapp.com/'><img class='footer-img' src="{% static 'assets/banner/ADB_SOF-01.jpg' %}"></a>

I have this so far, but not sure where to go with adding the img tag inside it. 到目前为止,我已经知道了,但是不确定在其中添加img标签的去向。

var $a = $("<a>", {href: value.url});
$("#banner").append($a)

You can use append to include the img : 您可以使用append包含img

var $a = $("<a>", {href: value.url}).append(
    $("<img>", {src: "{% static 'assets/banner/ADB_SOF-01.jpg' %}"})
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM