简体   繁体   English

Javascript/Jquery 未定义的文本区域值

[英]Javascript/Jquery UNDEFINED textarea value

I run a website and there is an area to send messages with AJAX.我运行一个网站,并且有一个区域可以使用 AJAX 发送消息。 I've noticed that some messages say undefined and therefore people can't use the message system.我注意到有些消息说未定义,因此人们不能使用消息系统。 The following is the code used to get the value from the text area, whats wrong with it?以下是用于从文本区域获取值的代码,它有什么问题? I'm thinking that some browsers don't accept it so how can I fix it?我在想某些浏览器不接受它,那么我该如何解决呢? Thanks谢谢

<textarea id="message"></textarea>
$('textarea#message').val()

The val() method get the value attribut, but tag textarea has no value attribut. val()方法获取 value 属性,但 tag textarea 没有 value 属性。 The text inside Textarea is saved inside the tags <textarea> and </textarea> , so you have to use $('textarea#message').text() . Textarea 中的文本保存在标签<textarea></textarea>中,因此您必须使用$('textarea#message').text() It should work.它应该工作。

  <textarea >some text</textarea >

   not like this

   <textarea value="some text"></textarea >

There is no value attribute没有价值属性

  <textarea id="message"></textarea>
  $('textarea#message').text();

demo演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM