[英]How do you add a line break inside of a javascript variable using 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 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
。
我從未聽說過 Kinetic 文本,但基於此示例: http : //www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-text-tutorial/你應該這樣做:
text: 'where text goes\\n\\nwhere text goes',
使用 html() 而不是 'text' 和 'val'
.html('這里使用一些 -br- 簡單文本');
結果:使用一些
簡單的文字在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.