【问题标题】:jQuery textarea value does not work properly with space and return keyjQuery textarea 值不适用于空格和返回键
【发布时间】:2012-12-30 11:03:57
【问题描述】:

我正在使用 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

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

如果是MyText,就可以了。

如果是My Text,它将为空!。

如果是

My

Text

它将是MyText

解决方案:

我在

中找到了解决方案

Jquery .val() not returning line-breaks in a textarea

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

非常感谢

【问题讨论】:

  • 尝试使用 $('textarea_id').html()
  • @nettle 我们不能使用val().prop('value') 有正当理由吗?
  • 能和this other post类似吗?
  • 您发布的代码运行良好且有效。你真的需要为你的问题设置一个演示。 jsbin.com/ixohis/1/edit 编辑这个,直到你做错了:D
  • 在这里工作正常jsfiddle.net/7ndM8 它要么是其他东西,要么是特定于浏览器的。

标签: php javascript jquery html


【解决方案1】:

我在

中找到了解决方案

Jquery .val() not returning line-breaks in a textarea

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

【讨论】:

    猜你喜欢
    • 2013-04-08
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多