如何在按钮单击下捕获文本框的按键值 [英] How to capture the keypress values of textbox under button click

查看:96
本文介绍了如何在按钮单击下捕获文本框的按键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按钮单击下捕获文本框的按键值.

How to capture the keypress values of textbox under button click.

推荐答案

我认为文本框具有焦点,以便您在其中键入内容(即,键).

使用 onkeyup 事件(由于已实施更改,因此我发现它很容易)来使用DOM来获取文本框的值.您的文本框将需要一个id ="something'',以便 document.getElementById(``something'').value 返回您文本框的内容.

如果只希望在单击按钮时捕获数据,请使用 onclick 事件并执行相同的操作.

顺便说一下,您也可以在此时修改内容,例如更改大小写,将输入限制为仅某些字符,格式(如电话号码)或javaScript可以执行的几乎所有操作.

I presume you textbox has the focus in order for you to type into it (i.e., keypress).

Use the onkeyup event (I find it easier as the change has already been implemented) to use the DOM to get the value of your textbox. Your textbox will need an id=''something'' so that document.getElementById(''something'').value returns your textbox''s content.

If you only wish to capture the data upon a button click, use the onclick event and do the same thing.

You can, by the way, modify the content at this time, too, such as changing case, limiting input to only certain characters, formatting (like telephone number), or pretty much anything javaScript can do.


这篇关于如何在按钮单击下捕获文本框的按键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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