如何在javascript中检索文本区域的值 [英] How to retrieve the value of a text area in javascript
问题描述
var body = $(#txtBody)。val (); //将数据库'undefined'添加到
var body = $(#txtBody)。 //对数据库没有添加
var body = $(#txtBody)。html(); //将数据库'NULL'添加到数据库
我无法想像如何访问数据。任何想法?
你说添加到数据库。您是否调试了实际的代码,以确保您不仅仅是用一个变量名发送数据,并尝试用另一个变量名来添加它们?因为如果你有这样的字段:
< input type ='text'id ='txtBody'value ='test >
或像这样:
< textarea id ='txtBody'> test< / textarea>
执行 $('#txtBody')。val() code> 将返回值test。没有ifs或buts关于它。
也许你应该发布更多的代码,所以我们可以发现什么是错的,因为我猜这不是你的实际问题正在拥有。
I have a form with a text area input. I'm using JQuery to submit the form via an AJAX request in order to update a database. My problem is that I'm having difficulty retrieving the data from the text area input. If the input has an id of "txtBody" I have tried:
var body = $("#txtBody").val(); // This adds 'undefined' to the database
var body = $("#txtBody").text(); // This adds nothing to the database
var body = $("#txtBody").html(); // This adds 'NULL' to the database
I can't think of how else to access the data. Any ideas?
You say adds to the database. Have you debugged the actual code to make sure you're not just sending the data with one variable name and trying to add it with another? Because if you have a field like this:
<input type='text' id='txtBody' value='test'>
Or like this:
<textarea id='txtBody'>test</textarea>
Doing $('#txtBody').val();
will return the value "test". There's no ifs or buts about it.
Maybe you should post some more of your code so we can spot what is wrong, as I am guessing that's not the actual problem you are having.
这篇关于如何在javascript中检索文本区域的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!