我不知道如何用语言表达,所以请多多包涵。
我有一个虚拟键盘。其中有一个“退格”按钮(div),每次单击都会删除一个字符。我希望它更现实。所以问题是“如果用户按下鼠标,我如何删除多个字符(即连续按下鼠标并且用户没有将手指从鼠标上移开)”
<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);
}