移动设备的按键事件

移动设备的按键事件

本文介绍了jQuery:移动设备的按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iPhone 上触发 keyup 事件时遇到了一些问题,我的代码如下:

I'm having a few issues getting a keyup event to fire on my iPhone, my code is as follows:

        var passwordArray = ["word", "test", "hello", "another", "here"];

        var test = document.getElementById('enter-password');
        test.addEventListener('keyup', function(e) {

            if (jQuery.inArray(this.value, passwordArray) != -1) {
                alert("THIS IS WORKING");
            } else {}

        });

这个想法是,当用户在 #enter-password 字段中输入时,当他们在 passwordArray 中匹配一个单词时,警报将触发.这适用于桌面,例如一旦您输入word,该功能将在您输入d 后立即触发.有没有办法让它也适用于移动设备?

The idea being that as the user is typing into the #enter-password field, as and when they've matched a word in the passwordArray the alert will fire. This works on desktop, e.g. once you've entered word the function will fire straight away as soon as you've typed the d. Is there anyway to get this to work for mobile too?

推荐答案

您可以添加输入事件.这是一个每当输入改变时触发的事件.输入法适用于台式机和手机

You can add input event. It is an event that triggers whenever the input changes. Input works both on desktop as well as mobile phones

test.on('keyup input', function(){
  //code
});

您可以查看此答案以了解有关 jQuery 输入事件

You can check this answer for more details on jQuery Input Event

这篇关于jQuery:移动设备的按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:08