gpt4 book ai didi

字符串上的 JavaScript 下一行(\n)不起作用

转载 作者:行者123 更新时间:2023-11-28 07:23:01 25 4
gpt4 key购买 nike

嗨,这没有意义,我试图用\n 来打破我的句子,但它似乎不起作用,我的代码如下

 "Address:"+location.addressLine1 + " " + location.addressLine2 +"\n "+"Store Name:\n"+ location.storeName +" "+"Geofence:\n"+ location.maxGeofence+" "+"City:\n"+location.city

我的目标是将所有行换成新行,如下所示

Address:xxxxxxx

Store Name:xxxxxx

Gofence:xxxxxx

City:xxxxxxx

但是我一直在努力

 Address:xxxxxxx Store Name:xxxxxx Gofence:xxxxxx  City:xxxxxxx

最佳答案

使用<br/>在 HTML 中,或者,如果您希望继续使用 \n ,使用nl2br来自 php.js 的函数:

function nl2br (str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}

这将转换每个 \n<br/>

关于字符串上的 JavaScript 下一行(\n)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30073544/

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