Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在“内部指定变量值”&引用;javascript_Javascript_Jquery - Fatal编程技术网

如何在“内部指定变量值”&引用;javascript

如何在“内部指定变量值”&引用;javascript,javascript,jquery,Javascript,Jquery,我的代码 成功:函数(结果){ var htmlString=''; htmlString+='画像 result.titleresult.content1

我的代码

成功:函数(结果){
var htmlString='';
htmlString+='画像 result.title

result.content1

result.content2

; $('#addItem')。在(htmlString)之前; },

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

您的变量现在只是一个字符串。要使变量的值显示在字符串中,您必须将字符串切分为片段,并使用加法运算符像这样添加变量

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);
},

您的变量现在只是一个字符串。要使变量的值显示在字符串中,您必须将字符串切分为片段,并使用加法运算符像这样添加变量

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);
},
使用ECMAScript 2015的

varid=5;
var image=“myimage.jpg”;
警惕(``);
警报(``)
使用ECMAScript 2015

varid=5;
var image=“myimage.jpg”;
警惕(``);
警报(``)

很好的解释,恭喜!仍然不起作用
htmlString+=”它的not quotes(“”)模板文本被后面的勾号(``)括起来。谢谢你的回答,我保存了2h:),而不是在字符串中使用操作。再次感谢。@ChungDo很高兴这有帮助很好的解释,恭喜!仍然不起作用
htmlString+=”它的not quotes(“”)模板文本被后面的勾号(``)括起来。谢谢你的回答,我保存了2h:),而不是在字符串中使用操作。再次感谢。@Chungo很高兴它有帮助
var id = 5;
var image = "myimage.jpg";
alert(` <div id=\"${id}\">`);
alert(` <img src=\"${image}\">`)