Create HTML tag from Javascript object

前端 未结 6 2074
清歌不尽
清歌不尽 2021-02-19 06:21

What is the best method to change this object

{
    src: \'img.jpg\',
    title: \'foo\'
}

into a valid HTML tag string like t

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-19 06:32

    Making html elements based out of objects containing attribute-attribute values such as

    {
        src: 'img.jpg',
        title: 'foo'
    }
    

    almost completely falls into the paradigm of cook.js.
    The command which you would issue with cook would be:

    img ({
        src: 'img.jpg',
        title: 'foo'
    })
    

    If the attribute details are stored as given in your example,
    in a variable obj then:

    img(obj)
    

    For more details check it out at cook.relfor.co.

提交回复
热议问题