1

要么我搜索错了,要么我根本找不到答案。

我想使用 JSP 制作一个简单的聊天应用程序。我想从一个字段(输入)中获取文本并将其附加到大文本区域(输出)中,然后清除文本字段(输入)并刷新页面。每个条目都应该在它自己的行上。

来自Java,这似乎很令人困惑,我已经研究了很长时间来尝试弄清楚。请问你能帮帮我吗?

<html>
    <head>
        <script>
            function send() {

            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Simple Chat</title>
    </head>
    <body>
        <h1>Simple Chat</h1>
        <textarea rows="30" cols="100" name="output">Welcome to the Chat!</textarea>
        <form name="input">
            <input type="text" name="input">
            <input type="button" name="sendBtn" value="Send" onClick="send()">
            <input type="button" name="refreshBtn" value="Refresh" onClick="location.href='chat.jsp'">
        </form>
    </body>
</html>
4

1 回答 1

1
<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
        <script>
            function send() 
            {
                $("#txtArea").append("\n" + $("#txt").val());
                $("#txt").val("");
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Simple Chat</title>
    </head>
    <body>
        <h1>Simple Chat</h1>
        <textarea id="txtArea" rows="30" cols="100" name="output">Welcome to the Chat!</textarea>
        <div name="input">
            <input id="txt" type="text" name="input">
            <input type="button" name="sendBtn" value="Send" onClick="send()">
            <input type="button" name="refreshBtn" value="Refresh" onClick="location.href='chat.jsp'">
        </div>
    </body>
</html>
于 2012-12-05T13:00:16.413 回答