gpt4 book ai didi

PHP 将换行符打印到文本区域

转载 作者:行者123 更新时间:2023-11-28 16:31:37 25 4
gpt4 key购买 nike

我正在尝试将换行符打印到文本区域中。

我有这个字符串:

$coords = $row->lat.','.$row->lon."\r\n"

当我使用以下 JavaScript 命令时:

alert(coords); 

我得到:

-35.308401,149.124298
-35.307841,149.124298

但是,当我在文本区域中查看它时,我得到:

-35.308401,149.124298 -35.307841,149.124298

如何使换行符显示在文本区域中?

更多信息:

警报窗口显示:

alert window

文本区域: enter image description here

代码:

<textarea name="addrs" rows=5 cols=80>-35.308401,149.124298 -35.307841,149.124298</textarea>

更多信息:这就是创建表单并将文本写入文本区域的方式

function openMapWindow (data) {
alert(data);

var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "http://www.xxx.com/map.php";

var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);

document.body.appendChild(mapForm);

map = window.open("", "Map", "status=0,title=0,height=600,width=800,scrollbars=1");

if (map) {
mapForm.submit();
} else {
alert('You must allow popups for this map to work.');
}

}

function mapSuppliers(customer_id) {
$.get("get.map.points.php", { c_id: customer_id },
function(data){
if (data!='') {
openMapWindow(data);
} else {
alert("Missing map coordinates - cannot display map (data: " + data + ")");
}
});

}

最佳答案

您正尝试在输入字段中包含多行。

考虑将代码更新为:

var mapTextarea = document.createElement("textarea");
mapTextarea.name = "addrs";
mapTextarea.value = data;
mapForm.appendChild(mapTextarea);

关于PHP 将换行符打印到文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5691287/

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