gpt4 book ai didi

javascript - 如何使用 KineticJS 在 javascript 变量中添加换行符?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:59 24 4
gpt4 key购买 nike

我有一个看起来像这样的变量:

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 上下文(例如 nodeValueinnerText )中输出文本,则必须使用 \n 并确保容器的 CSS white-space 属性设置为某项不压缩空格,例如 pre-wrap

关于javascript - 如何使用 KineticJS 在 javascript 变量中添加换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16595483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com