jQuery 获取 textarea 文本 [英] jQuery get textarea text

查看:42
本文介绍了jQuery 获取 textarea 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始使用 jQuery,并且一直在学习一些教程.现在我觉得使用它有点能力(这很容易),我认为如果我能够在我的网页上制作一个控制台"会很酷(例如,你像在 FPS 游戏等),然后将它的 Ajax 本身带回服务器以便做东西.

Recently I have started playing with jQuery, and have been following a couple of tutorials. Now I feel slightly competent with using it (it's pretty easy), and I thought it would be cool if I were able to make a 'console' on my webpage (as in, you press the ` key like you do in FPS games, etc.), and then have it Ajax itself back to the server in-order to do stuff.

我最初认为最好的方法是将文本放入 textarea 中,然后将其拆分,或者我应该使用 keyup 事件,将返回的键码转换为 ASCII 字符,将字符附加到字符串并发送字符串到服务器(然后清空字符串).

I originally thought the best way would be to just get the text inside the textarea, and then split it, or should I use the keyup event, convert the keycode returned to an ASCII character, append the character to a string and send the string to the server (then empty the string).

我找不到任何关于从 textarea 获取文本的信息,我得到的只是 keyup 信息.另外,如何将返回的键码转换为 ASCII 字符?

I couldn't find any information on getting text from a textarea, all I got was keyup information. Also, how can I convert the keycode returned to an ASCII character?

推荐答案

为什么要将按键转换为文本?添加一个按钮,在单击时将 textarea 内的文本发送到服务器.您可以使用 value 属性作为海报之前指出的文本,或者使用 jQuery 的 API:

Why would you want to convert key strokes to text? Add a button that sends the text inside the textarea to the server when clicked. You can get the text using the value attribute as the poster before has pointed out, or using jQuery's API:

$('input#mybutton').click(function() {
    var text = $('textarea#mytextarea').val();
    //send to server and process response
});

这篇关于jQuery 获取 textarea 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆