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

问题描述 投票:5回答:3

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

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有效

javascript kineticjs
3个回答
7
投票

如果输出到HTML,例如innerHTML,则只需使用<br />

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


0
投票

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

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


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.