检测表单中的按键? [英] Detecting a keypress within a form?

查看:121
本文介绍了检测表单中的按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让一个网页检测特定形式的用户按键(每个按键上都有一个要调用的功能).但是我的代码不起作用(控制台从不打印到日志中):

I'm trying to get a web page detect user keypresses within a particular form (there is a function to be called on each keypress). However my code is not working (console never prints to the log):

$(document).on("keypress","filterinput",function(e) {
    console.log("press detected");
});

<form class="filterform"><input class="filterinput" type="text"></form>

推荐答案

您在类选择器中忘记了.:

You forgot the . in the class selector:

$(document).on("keypress", ".filterinput", function(e) {
//                          ^ this . indicates that it's a class selector
    console.log("press detected");
});

这篇关于检测表单中的按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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