jQuery textarea值与空格和返回键不能正常工作


jQuery textarea value does not work properly with space and return key

我正在使用PHP和jquery。

我得到textarea的值jquery命令:

$('#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$textarea_content = $_REQUEST['textarea_content'];

如果我使用echo $textarea_content查看文本区内容

MyText的情况下,它将是好的。

My Text的情况下,它将为null!

My

Text

它将是MyText

解决方案:

我在

中找到了解决方案

Jquery .val()在textarea中不返回换行符

解决方案是:encodeURIComponent($('#textarea_id').val())

多谢

我在

中找到了解决方案

Jquery .val()在textarea中不返回换行符

解决方案是:encodeURIComponent($('#textarea_id').val())