如何使用KineticJS在javascript变量内添加换行符? [英] How do you add a line break inside of a javascript variable using KineticJS?
本文介绍了如何使用KineticJS在javascript变量内添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的变量:
I have a variable that looks like this:
var simpleText = new Kinetic.Text({
text: 'where text goes',
fontSize: 24
});
如何在文本所在的位置插入换行符.我尝试过:
How do I insert a line break where the text goes. I've tried:
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 />
.
If you are outputting to HTML, such as with innerHTML
, just use <br />
.
但是,如果要在HTML上下文中输出文本(例如nodeValue
或innerText
),则必须使用\n
并确保容器的CSS white-space
属性设置为不能消除空格,例如pre-wrap
.
If, however, you are outputting to text in an HTML context (such as nodeValue
or innerText
, you will have to use \n
and ensure that the container has the CSS white-space
property set to something that doesn't condence whitespace, such as pre-wrap
.
这篇关于如何使用KineticJS在javascript变量内添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文