spread html in multiple lines javascript

前端 未结 4 1682
轻奢々
轻奢々 2021-02-05 21:09

I want to put the below html code in my javascript function. I don\'t want to put it all next to each other. Is it possible to the code in the same way as how it is in html? Cod

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 21:38

    Really old question, but I don't find this syntax a lot, so I'll just leave this here, as to me it is the most readable.

    var html = '' +
        '    ';
    

    With a simple shell command to generate this from an html file:

    cat myfile.html | sed "s/'/\\'/g" | sed "$ ! s/^.*$/'\0' +/g" | sed "$ s/^.*$/'\0';/"
    

    Update: With ES6, simply use backticks:

    const html = `
      
    `;

提交回复
热议问题