gpt4 book ai didi

javascript -\n 换行符不起作用

转载 作者:行者123 更新时间:2023-12-04 06:50:21 34 4
gpt4 key购买 nike

我试过写一个网页

document.write("This is the first line \n And this is the second");

想要的效果是:

This is the first line
And this is the second

但是我明白了:

This is the first line And this is the second

我试着写 <br>在里面,它起作用了。但是为什么要写转义 \n没有?我做错了什么吗?我正在使用 Firefox。

最佳答案

你没有做错任何事。它只是 \n字符在文本相关元素中有效,例如 alert() 和 <textarea> .

document.write()命令写入站点正文或显示(在 HTML 中)。替代<br>代替 \n在这里,因为你正在页面中编写 HTML

关于javascript -\n 换行符不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14518829/

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