ai didi

javascript - 如何在 ""javascript 中指定变量值

转载 作者:行者123 更新时间:2023-12-02 14:12:46 24 4
gpt4 key购买 nike

我的代码

success: function(result) {
var htmlString = '';
htmlString+= '<div class=\"row mgt45 bg-delete\"><div class=\"col-sm-5\"><div class=\"p-relative\"><img id=\"logoImg\" src=\"result.image\" width=\"100%\"><button id=\"result.id\" class=\"change-img topleft\" data-toggle=\"modal\" data-target=\"#myModal\"><i class=\"fa fa-camera\" aria-hidden=\"true\"></i> 画像</button></div> </div><div class=\"col-sm-7 corp-office\"><h2 id=\"title_result.id\" class=\"changeableFacility\" contenteditable=\"true\">result.title</h2><p id=\"content1_result.id\" class=\"changeableFacility\" contenteditable=\"true\">result.content1</p><p id=\"result.content2\" class=\"changeableFacility\" contenteditable=\"true\">result.content2</p></div><span id=\"delete_result.id\" href=\"\" class=\"btn-delete\"><i class=\"fa fa-times-circle\" aria-hidden=\"true\"></i></span> </div>';

$('#addItem').before(htmlString);
},

如何将 result.idresult.image 存储为变量而不是字符串?

最佳答案

使用 ECMAScript 2015 的 Template String Literals

var id = 5;
var image = "myimage.jpg";
alert(` <div id=\"${id}\">`);
alert(` <img src=\"${image}\">`)

关于javascript - 如何在 ""javascript 中指定变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39360945/

24 4 0
文章推荐: javascript - 在交叉过滤器数组维度上进行 AND 过滤
文章推荐: javascript - 自定义 onbeforeunload 消息
文章推荐: javascript - 最终显示不正确的 radio 值..不明白为什么
文章推荐: javascript - 如何在 Angular-J 中使用 ArcGIS map ?
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com