javascript - 将带有类 ID 和图像的 div 添加到容器

标签 javascript jquery html css

我已经为此苦苦挣扎了几天。我想将带有类 id 的 div 和图像附加到我的容器中,我已经能够渲染卡片,但是在检查开发工具中的 HTML 时,我遇到了这个

<div class="hidden-container card-image" id="card-id-1" "=""> 
<img src="../images/avatar.png" <="" div="">
</div>

让我惊讶的是空的= <=和空div 。这些显然不应该在这里。

我像这样渲染 div

    $.each(cards, function (index, props) {
        $("#card-area").append('<div class="hidden-container card-image" id=card-id-' + props.Id + ' "> <img src="' + props.Url + '"</div>');
    });

有人能正确格式化这个吗?这几天一直让我头疼。

最佳答案

1.您错过了"左右id

2.您错过关闭<img>标签也是如此

$.each(cards, function (index, props) {
  $("#card-area").append('<div class="hidden-container card-image" id="card-id-' + props.Id + ' "> <img src="' + props.Url + '"></div>');
});

关于javascript - 将带有类 ID 和图像的 div 添加到容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60900955/

相关文章:

javascript - 在 javaScript css 声明中打破字符串?

javascript - 如果结束日期低于开始日期,则增加结束日期

HTML5/CSS3 : How Do I Prevent LI Items From Being Pushed To The Right with No Bullet Without Using JavaScript or PHP?

jquery - 滚动上的动画进度条

jquery - 将行垂直对齐到 100% 高度

html - 如何制作粘性标题?

javascript - 用这个。在 Angular 不起作用?

javascript - 如何使用 angular 或 javascript 根据 true/false 返回值在 html 中显示值?

javascript - 如何使用正则表达式提取文本?

javascript - 为什么 Node 在脚本和 repl 中执行不同的正则表达式匹配?