a more graceful multi-line javascript string method

后端 未结 5 594
轻奢々
轻奢々 2021-01-12 04:22

The only way I know how to print a huge string without using += is to use \\ backslashes. ugly!

5条回答
  •  清歌不尽
    2021-01-12 04:42

    You really could minimize this ugliness by creating your

    as HTML, and set its content with .innerHTML = "test content. maybe some code"

    I don't like creating HTML in Javascript because of this exact issue, and instead use "template" elements which i simply clone then manipulate.

    var lol = document.getElementById("template_lol").clone();
    lol.firstChild.innerHTML = "code and stuff";
    foo.appendChild(lol);
    

    And this is the HTML:

    
    
    normal stuff

提交回复
热议问题