Appending large block of html with append()

后端 未结 11 1041
-上瘾入骨i
-上瘾入骨i 2021-01-31 10:09

Im trying to append a large block of text using jquery\'s append().

$(\'#add_contact_btn\').click(function(event) {
    event.preventDefault();

    var large =         


        
11条回答
  •  萌比男神i
    2021-01-31 10:47

    Modern Answer

    As ES6 (and beyond) becomes more common, and as more and more people transpile from ES6, we are more and more able to use template literals, which can be used as multiline strings:

    var myString = `

    Line One

    Line Two

    Line Three

    `;

    Original 2012 Answer (ES5)

    Javascript does not have multiline strings in the way you are writing them, you can't just open a string on one line, go down a few lines and then close it. (there are some ways of doing multi-line strings in JS, but they are kind of backwards).

    How most people do it is something like this:

    var myString = '

    Line One

    ' + '

    Line Two

    ' + '

    Line Three

    ';

提交回复
热议问题