jQuery的获得textarea的文本 [英] jQuery get textarea text

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

问题描述

最近我已经开始使用jQuery玩,并一直在关注几个教程。现在我觉得稍微主管与使用它(这是pretty的方便),我认为这将是冷静,如果我能够做一个控制台在我的网页(如,你preSS`键像你在 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.

我本来以为最好的办法是将刚刚得到的文本区域内的文本,然后把它分解,或者我应该使用KeyUp事件,转换键code返回到一个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信息。另外,我怎么能转换的关键code返回到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天全站免登陆