jQuery不会显示包含行制动器的文本的变量

时间:2013-05-06 14:03:44

标签: jquery newline

为什么当我有一个包含换行符的变量时jQuery不起作用:

这有效:

var text = "This is my text and it works fine";

这不是:

var text = "this is my text
            and it does not work";

这有什么办法吗? 我正在尝试创建一个包含数据库中文本的变量,它可能包含换行符,标记...

2 个答案:

答案 0 :(得分:1)

尝试下面

var text = "this is my text";
   text += " and it does not work";

OR

var text = "this is my text" +
       " and it does not work";

OR

var text = "this is my text  \
       and it DOES  work now";

答案 1 :(得分:0)

以下方式是正确的 -

var text = "this is my text " +
           "and it DOES  work now! ";

选中此demo