use*_*479 4 javascript kineticjs
我有一个看起来像这样的变量:
var simpleText = new Kinetic.Text({
text: 'where text goes',
fontSize: 24
});
Run Code Online (Sandbox Code Playgroud)
如何在文本所在的位置插入换行符.我试过了:
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',
Run Code Online (Sandbox Code Playgroud)
我的错误.\n有效
如果要输出到HTML,例如with innerHTML,只需使用<br />.
但是,如果要输出到HTML上下文中的文本(例如,nodeValue或者innerText,则必须使用\n并确保容器将CSS white-space属性设置为不符合空格的内容,例如pre-wrap.