如何使用KineticJS在javascript变量内部添加换行符?

如何使用KineticJS在javascript变量内部添加换行符?,javascript,kineticjs,Javascript,Kineticjs,我有一个变量如下所示: var simpleText = new Kinetic.Text({ text: 'where text goes', fontSize: 24 }); 如何在文本所在位置插入换行符。我试过: text: 'where text goes \n where text goes', text: 'where text goes \n\n where text goes', text: 'where text goes \r\n where tex

我有一个变量如下所示:

var simpleText = new Kinetic.Text({
    text: 'where text goes',
    fontSize: 24
  });
如何在文本所在位置插入换行符。我试过:

text: 'where text goes \n where text goes',

text: 'where text goes \n\n where text goes',

text: 'where text goes \r\n where text goes',

text: 'where text goes <br /> where text goes',

text: 'where text goes \n' + 'where text goes \n',

text: 'where text goes ' + 'where text goes ',

text: 'where text goes ' 
+ 'where text goes ',

text: 'where text goes 
where text goes',
text:“文本去哪里\n文本去哪里”,
text:“文本的去向\n\n文本的去向”,
text:“文本的去向\r\n文本的去向”,
text:“文本的去向
文本的去向”, text:'文本的去向\n'+'文本的去向\n', text:“文本的去向”+“文本的去向”, 文字:“文字的去向” +“文本的去向”, 文本:文本的去向 文本去哪里‘,

我这边的错误\如果要输出到HTML,例如使用
innerHTML
,只需使用

,n就可以工作


但是,如果您正在输出到HTML上下文中的文本(例如
nodeValue
innerText
,您必须使用
\n
,并确保容器的CSS
空白
属性设置为不压缩空白的内容,例如
预包装

我从未听说过动态文本,但基于此示例:您应该:

text:“文本去哪里\n\n文本去哪里”

使用html()而不是“text”和“val”

.html('此处使用一些-br-简单文本')

结果:使用一些

这里的简单文本

可能是输出HTML,所以请使用

而不是
\n
。否则,您的第一个示例应该可以工作。感谢您的建议,但这不起作用,它不输出HTML。而且,当我使用\n时,它根本不输出任何文本。您使用的是此库吗?:是的,我使用的是@IanI使用的
\n
在我的工作中…因此错误一定在其他地方。尝试设置断点,dig inIt没有说要使用
\n\n
。它有两个换行符。请注意输出中的额外行…感谢您的建议,不幸的是,这也不起作用。我将更新我的问题。谢谢@Ian,我没有看到。\n不起作用,也没有是
。对不起,我忘了提到我正在使用KineticJS。