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

问题描述

我遇到一些问题,要在我的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
});

您可以查看此答案以获取有关

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

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

09-02 15:21