Javascript中三引号字符串的替代方法,如Python

2024-05-18 05:13:44 发布

您现在位置:Python中文网/ 问答频道 /正文

Python有三个带引号的字符串,可以提供免费的文本输入。不需要下一行字符来定义下一行。这里有一个例子

 hello = """

            This string is bounded by triple double quotes (3 times ").
        Unescaped newlines in the string are retained, though \
        it is still possible\nto use all normal escape sequences.

            Whitespace at the beginning of a line is
        significant.  If you need to include three opening quotes
        you have to escape at least one of them, e.g. \""".

            This string ends in a newline.
        """

所以我有一个HTML文本,由段落组成。我可以在段落之间使用空格,但我认为如果javascript具有类似Python的三引号字符串的功能,我可以使用它生成段落。

在Javascript中是否有类似于Python的其他免费文本用法,或者您是否可以建议Javascript库这样做?

谢谢你!


Tags: oftheto字符串in文本youstring