2013-05-16 28 views
3

我有一个变量,它看起来像这样:我要如何插入一个换行符在文云如何使用KineticJS在JavaScript变量内添加换行符?

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作品

+2

它可能输出HTML,所以使用'
'而不是'\ n'。否则,你的第一个例子应该工作。 – Ian

+0

感谢您的建议,但不起作用,它不会输出html。另外,当我使用\ n它根本不输出任何文本。 – user761479

+0

您是否在使用此图书馆?:https://github.com/ericdrowell/KineticJS – Ian

回答

4

如果要输出为HTML,例如使用innerHTML,则只需使用<br />即可。

但是,如果你是输出到HTML上下文文本(如nodeValueinnerText,你将不得不使用\n并确保容器具有CSS white-space属性设置为一些不置信的空白, 。如pre-wrap

+1

\ n不工作也不
。抱歉,我忘记提及我正在使用KineticJS。 – user761479

相关问题