通过JSP在脚本上获取textarea编辑的文本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过JSP在脚本上获取textarea编辑的文本相关的知识,希望对你有一定的参考价值。

我需要使用JSP的脚本来获取用户在文本区域中输入的文本。我尝试了这段代码,但得到空值:

<label for="userText"></label>
            <textarea name="userText" id="userText">text edited by the user</textarea>
            <button onclick="myFunction()">Ok</button>

function myFunction() {
        <%System.out.print(request.getParameter("userText"));%>
    }

我能得到吗?

答案

您将为此使用Java脚本

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

以上是关于通过JSP在脚本上获取textarea编辑的文本的主要内容,如果未能解决你的问题,请参考以下文章