[英]Textarea - missing new line
我有以下代碼:
<form action="../p/padd.php" method="POST">
<input type="button" value="Náhľad" OnClick="javascript:nahlad()" />
<textarea tabindex="4" id="textra" name="text" ></textarea>
<input type="submit" value="Vložiť" />
</form>
<span id="nahlad"> </span>
<script>
function nahlad()
{
var textra = document.getElementById("textra").value;
alert (textra);
var xmlhttp;
if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();
}
else
{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('nahlad').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","ssnahlad.php?text=" + textra,true);
xmlhttp.send();
}
</script>
當我在textarea中輸入以下內容時(是的,在enter中有“換行”)
asd
asd
然后單擊Nahlad按鈕
ssnahlad.php包含
<?php
$new = $_GET['text'];
echo nl2br($new);
?>
那么為什么id = nahlad的跨度包含
asdasd
代替
asd
asd
現在我可以在家進行測試了,這可以正常工作:
var newText = encodeURIComponent(textra);
在發送前使用encodeURIComponent可以正確呈現您的輸出,而在服務器端不進行解碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.