[英]jQuery textarea value does not work properly with space and return key
我正在將PHP與jquery一起使用。
我通過jquery命令獲取textarea值:
$('#textarea_id').val()
如果我在textarea中使用空格,例如My Text
,則只會得到My
。
如果我在文本區域中使用返回鍵,例如
My
Text
它作為MyText
編輯:
似乎$('#textarea_id').val()
確實有效。
實際上,我正在使用類似
func1(...,$('#textarea_id').val(),...);
在func1
,我有:
function func1(...,textarea_content,...) {
$('#textarea_id').load('/test.php?textarea_content=' + textarea_content + ...);
}
並且也在test.php
我使用$textarea_content = $_REQUEST['textarea_content'];
獲取textarea_content
$textarea_content = $_REQUEST['textarea_content'];
如果我使用echo $textarea_content
查看textarea內容。
如果是MyText
,那就可以了。
如果是“ My Text
,則為null !。
並且在
My
Text
這將是MyText
解:
我在找到解決方案
解決方案是: encodeURIComponent($('#textarea_id').val())
非常感謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.