对点击重复执行操作 [英] Performing action repetitively on a click

查看:163
本文介绍了对点击重复执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该如何把这个词,所以请和我一起。

i am not sure how to put this in words,so kindly bear with me .

我有一个虚拟键盘。在它有一个退格按钮(div),删除每次点击的字符。
我想要更逼真。所以问题是如果用户按下鼠标时,如何删除多个字符(即连续按下鼠标,用户没有将手指从鼠标上取下)

I have a virtual keypad. In it there is a "backspace" button(div) that deletes a character on each click . i want it to be more realistic . so the question is "How do i delete multiple characters if the user is pressing the mouse down (i.e the mouse is pressed continously and the user hasn't lift his finger off the mouse )"

<div class="dialpadnumbers">1</div>
<div class="dialpadnumbers">2</div>
<div class="dialpadnumbers">3</div>
<div class="dialpadnumbers">4</div>
<div class="dialpadnumbers">5</div>
<div class="dialpadnumbers">6</div>
<div class="dialpadnumbers">7</div>
<div class="dialpadnumbers">8</div>
<div class="dialpadnumbers">9</div>
<div class="dialpadnumbers">0</div>
<div id="dialpadbackspace" class="dialpadnumbers">Backspace</div>
<div id="dialpadcall" class="dialpadnumbers">CALL</div>

/*also the jquery for it(the one ive been using till now is),caret is the fn          
for setting caret position*/
$("#dialpadbackspace").click(function() {
    $('#dialpadentry').focus();
    var init = $("#dialpadentry").val();
    var start = $("#dialpadentry")[0].selectionStart;
    var stop = $("#dialpadentry")[0].selectionEnd;
    if (start == stop) {
        var substr = init.substring(0, start);
        var newsubstr = init.substring(0, start - 1);
        var finale = init.replace(substr, newsubstr);
        $("#dialpadentry").val(finale);
        $('#dialpadentry').caret(start - 1);
    } else {
        var substr = init.substring(start, stop);
        var finale = init.replace(substr, '');
        $("#dialpadentry").val(finale);
        $('#dialpadentry').caret(start);
    }


推荐答案

on mousedown启动一个间隔,它每隔x毫秒调用一个函数,从拨号中删除一个字符。你已经有两个很好的答案,所以我只会发布一个快速jsfiddle我做了。

Basically on mousedown start a interval which calls a function every x milliseconds that removes a character from the dial. You already got two excellent answers, so I will just post a quick jsfiddle I did.

http://jsfiddle.net/EB29c/

这篇关于对点击重复执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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