val() vs. text() for textarea
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using jQuery, and wondering if I should use val() or text() (or another method) to read and update the content of a textarea. I have tried both and I've had issues with both. When I use text() to update textarea, line breaks (\n) don't work. When I use val() to retrieve the textarea content, the text gets truncated if it's too long. 回答1: The best way to set/get the value of a textarea is the .val() , .value method. .text() internally uses the .textContent (or .innerText for IE) method to get the contents of a . The following