如何在jquery中获取textarea的值?

时间:2022-11-12 14:58:30

How to get Textarea value in jquery, if I am using

如果我正在使用,如何在jquery中获取Textarea值

<form name="myform"> 
<textarea name="msg" id="msg"></textarea>
</form>

This syntax is not working properly

此语法无法正常工作

 var text = $('textarea#message').val();

can anybody tell me about the things ?

任何人都可以告诉我这些事情吗?

6 个解决方案

#1


7  

Your idea is right, but your selector is a bit off:

你的想法是正确的,但你的选择器有点偏:

$('textarea#msg').val(); //not "message"

The ID of the ID-selector needs to match exactly :)

ID选择器的ID需要完全匹配:)

#2


4  

$("#msg").val();

#3


2  

Have you tried:

你有没有尝试过:

$("textarea#msg").val(result.message);

or

$("textarea#msg").val()

#4


1  

You appear to be targeting the text area incorrectly. Try var text = $('textarea#msg').val().

您似乎错误地定位了文本区域。尝试var text = $('textarea#msg')。val()。

#5


0  

If your textarea's Id is "msg" then your selector needs to use that.

如果你的textarea的Id是“msg”,那么你的选择器需要使用它。

var text = $('textarea#msg').val();

#6


0  

your code :

你的代码:

<form name="myform"> 
<textarea name="msg" id="msg"></textarea>
</form>

Your id name is : msg, not message so your code should be like this :

您的ID名称是:msg,而不是消息,因此您的代码应该是这样的:

var text = $('textarea#msg').val();

#1


7  

Your idea is right, but your selector is a bit off:

你的想法是正确的,但你的选择器有点偏:

$('textarea#msg').val(); //not "message"

The ID of the ID-selector needs to match exactly :)

ID选择器的ID需要完全匹配:)

#2


4  

$("#msg").val();

#3


2  

Have you tried:

你有没有尝试过:

$("textarea#msg").val(result.message);

or

$("textarea#msg").val()

#4


1  

You appear to be targeting the text area incorrectly. Try var text = $('textarea#msg').val().

您似乎错误地定位了文本区域。尝试var text = $('textarea#msg')。val()。

#5


0  

If your textarea's Id is "msg" then your selector needs to use that.

如果你的textarea的Id是“msg”,那么你的选择器需要使用它。

var text = $('textarea#msg').val();

#6


0  

your code :

你的代码:

<form name="myform"> 
<textarea name="msg" id="msg"></textarea>
</form>

Your id name is : msg, not message so your code should be like this :

您的ID名称是:msg,而不是消息,因此您的代码应该是这样的:

var text = $('textarea#msg').val();