2011-04-17 111 views
0

我試圖將換行符打印到textarea中。PHP將換行打印到textarea中

我有這個字符串:

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

當我使用下面的JavaScript命令:

alert(coords); 

我得到:

-35.308401,149.124298 
-35.307841,149.124298 

然而,當我在觀看一個textarea,我得到:

-35.308401,149.124298 -35.307841,149.124298 

如何在textarea中顯示換行符?

更多信息:

警報窗口顯示:

alert window

textarea的: 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 + ")"); 
     } 
    }); 

} 
+0

hi Masume have a nice day! 

隨着PHP:

echo "hi Masume".chr(13)."have a nice day!"; 

隨着JS您的網絡瀏覽器的頁面,是否有線路回報,如你所期望的? – erisco 2011-04-17 03:43:31

+0

你說PHP,但你通過JS測試。你怎麼真的把數據傳遞給textarea?它是通過PHP內聯的嗎? – Khez 2011-04-17 03:49:04

+0

@Khez - 查看編輯 – 2011-04-17 03:56:57

回答

1

我知道這個問題是很老了,但我會後我的答案,以防萬一有人來這裏。

例如,如果我們想顯示這個文本在文本區域:當您查看源

textareaElement = 'hi Masume' + String.fromCharCode(13) + 'have a nice day!'; 
3

您試圖在輸入字段多行。

考慮更新您的代碼:

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

+1好點:) – Wh1T3h4Ck5 2011-04-17 04:11:43

+0

@ Wh1T3h4Ck5現在唯一令我困惑的事情是。是什麼似乎是一個textarea的截圖,但它可能是CSS。 – Khez 2011-04-17 04:13:03

+0

我仍然無法連接該PHP行和JS代碼。也許我錯過了一些東西,或者我太累了,此刻我的大腦不能正常工作。 – Wh1T3h4Ck5 2011-04-17 04:13:54