Display formatted raw html with jquery

后端 未结 2 1945
别跟我提以往
别跟我提以往 2021-01-16 03:39

I have a place where I am trying to show code in a text area. I have dumbed down the example but basically user can input some fields, click a button, and the code snippet

2条回答
  •  一向
    一向 (楼主)
    2021-01-16 04:36

    Add a \n if you want a new line like

    var mySnippet = "
    \n" + "
    \n" + "
    \n" + "
    \n"; $('#mySnippetArea').text(eventSnippet);

    Single character escape sequences:

    \b: backspace (U+0008 BACKSPACE)
    \f: form feed (U+000C FORM FEED)
    \n: line feed (U+000A LINE FEED)
    \r: carriage return (U+000D CARRIAGE RETURN)
    \t: horizontal tab (U+0009 CHARACTER TABULATION)
    \v: vertical tab (U+000B LINE TABULATION)
    \0: null character (U+0000 NULL)
    

    Example: http://jsfiddle.net/jtx7e/

提交回复
热议问题