Appending large block of html with append()

后端 未结 11 937
-上瘾入骨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条回答
  •  既然无缘
    2021-01-31 10:20

    By default, the HTML code containing wraps cannot be used with append/prependdirectly use 'or". However currently there are following methods to do that:

    1. Use "+" to join HTML code pieces.

    2. Use "\" to escape.

    3. Use "`" (back-tick, grave accent), do not need any extra operations. This method is supported from ES2015/ES6 (Template literals).

    4. Add a hidden tag containing the same HTML code you need, e.g.

      Now post some use scenarios to the first three methods metioned above (just run them in the console of Chrome browser.):

    We can see their differences clearly.

提交回复
热议问题