6

我有一个看起来像这样的变量:

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',

我的错误。\n 有效

4

3 回答 3

8

如果您要输出到 HTML,例如 with innerHTML,只需使用<br />.

但是,如果您要在 HTML 上下文中输出文本(例如nodeValueinnerText,则必须使用\n并确保容器的 CSSwhite-space属性设置为不包含空格的内容,例如pre-wrap.

于 2013-05-16T19:13:48.660 回答
0

我从未听说过动力学文本,但基于此示例:http ://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-text-tutorial/ 你应该这样做:

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

于 2013-05-16T19:14:30.457 回答
0

使用 html() 代替 'text' 和 'val'

.html('在这里使用一些-br-简单的文本');

结果:
在这里使用一些简单的文本

于 2020-03-10T20:11:43.000 回答