我不確定如何用文字表達,所以請耐心等待。通過點擊重複執行操作
我有一個虛擬鍵盤。在其中有一個「退格」按鈕(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);
}
看到這個http://stackoverflow.com/questions/4080497/jquery-detecting-click-and-hold – ManseUK 2012-07-26 14:50:48