简体   繁体   English

在JAVASCRIPT中更正HTML语法

[英]Correct HTML syntax in JAVASCRIPT

My problem is that I don't know the correct syntax for implementing html in a javascript snippet. 我的问题是我不知道在JavaScript代码段中实现html的正确语法。

I'm using simplecart.js and I would like to add a custom cart column with the color of one item in it, but I'm stuck with this since one hour. 我使用的是simplecart.js,我想添加一个自定义购物车列,其中包含一项的颜色,但是从一个小时开始,我就一直坚持下去。

{
    view: function (item, column) {
        "<div id='couleur'>
        <div style='background-color:'"
        return item.get('color')"'></div>
    </div>"
    },
    label: "Couleur"
},

Could anyone help me with this? 有人可以帮我吗?
Thanks a lot. 非常感谢。

You can not have line breaks in a string, you have nested double quotes, snd you have a function call that makes no sense. 您不能在字符串中有换行符,您必须嵌套双引号,这意味着您有没有意义的函数调用。

view: function (item, column) {
    var str = "<div id='couleur'>" +
              "<div style='background-color:" + item.get('color') + "'></div>" +
              "</div>";
    return str;
}

Most people would use more of a templating type of architecture. 大多数人会使用更多的模板类型的体系结构。

view: function (item, column) {
    var str = "<div id='couleur'><div style='background-color:{color}'></div></div>";
    return str.replace("{color}", item.get('color'));
}

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

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