如何使用 JQuery 捕获用户输入的文本?
我在页面上有以下输入元素:
Search: <input id="example" />
我想捕获用户在此框中输入的信息,当用户按 Enter 并将其显示在屏幕上时:
$(window).keypress(function(e) {
if(e.keyCode == 13) {
$("input[name=example]").val().insertAfter('#example');
}
以下结果是未定义的:
$("input[name=example]").val() is undefined
如何捕获用户输入的文本?
I have the following input element on the page:
Search: <input id="example" />
I would like to capture the information the user enters in this box, when the user hits enter and display it on screen:
$(window).keypress(function(e) {
if(e.keyCode == 13) {
$("input[name=example]").val().insertAfter('#example');
}
The following results in an undefined:
$("input[name=example]").val() is undefined
How do you capture user inputed text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您没有
名字
。使用
#
选择器:$('#example')
You don't have a
name
.Use the
#
selector:$('#example')
试试这个...
Try this...
由于您使用的是
id
而不是name
,请执行以下操作:Since you is using
id
and notname
, do: