Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 长按按钮每X毫秒调用一次功能_Javascript_Jquery_Html - Fatal编程技术网

Javascript 长按按钮每X毫秒调用一次功能

Javascript 长按按钮每X毫秒调用一次功能,javascript,jquery,html,Javascript,Jquery,Html,我正在为移动设备开发一个虚拟键盘 当用户长按backspace按钮时,我应该每隔X毫秒从输入文本中删除一个字母(就像普通移动设备的键盘一样) 如何编写此代码?您可以使用以下逻辑 var pressTimer; $("button").mouseup(function(){ clearTimeout(pressTimer); return false; }).mousedown(function(){ pres

我正在为移动设备开发一个虚拟键盘

当用户长按backspace按钮时,我应该每隔X毫秒从输入文本中删除一个字母(就像普通移动设备的键盘一样)


如何编写此代码?

您可以使用以下逻辑

  var pressTimer;
     $("button").mouseup(function(){
       clearTimeout(pressTimer);

         return false;
        }).mousedown(function(){

           pressTimer = window.setTimeout(function() { 
        },1000);
    timerListner();
        return false; 
        });

     fuction timerListner(){

        while(true){
          if(pressTimer %30 == 0){   //30 will be your interval 
               deleteWord();
           }
      if(pressTimer ==0){
            exit;
        }
  }

 } 

每X秒/ms
?请添加一些代码,也许是一个片段?不幸的是,它对我不起作用。它也在一个无限循环中运行。不管怎样,多亏了你的建议,我决定了。非常感谢。