我有一个看起来像这样的变量:
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有效
如果输出到HTML,例如innerHTML
,则只需使用<br />
。
但是,如果要在HTML上下文中输出文本(例如nodeValue
或innerText
,则必须使用\n
并确保容器的CSS white-space
属性设置为不使用空格,例如pre-wrap
。
我从未听说过动力学文字,但基于此示例:http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-text-tutorial/,您应该这样做:
text: 'where text goes\n\nwhere text goes',
使用html()代替'text'和'val'
。html('在这里使用一些-br-简单文本');
结果:使用一些简单的文字在这里