Tôi muốn phát hiện Điều khiển + A sự kiện trong đầu vào. Tôi có thể tìm thấy điều khiển + A sự kiện, nhưng chức năng vẫn tiếp tục sau return false
.Phát hiện Ctrl + A trong sự kiện keyup
jsFiddle - http://jsfiddle.net/f6rcgpmh/4/
$('.searchTerm').keyup(function(e) {
$("#status").text("");
if (e.ctrlKey) {
if (e.keyCode == 65 || e.keyCode == 97) { // 'A' or 'a'
console.log("Control pressed");
e.preventDefault();
return false;
}
}
$("#status").text("This should not work if Ctrl + A is pressed");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="search" class="search">
<input class="searchTerm" placeholder="Filter Books...">
<input class="searchButton" type="submit">
</form>
<div id="status"></div>
Tôi muốn điều này để làm việc trong keyup
không keydown
. Vì tôi đang sử dụng tính năng tự động tìm kiếm và tôi không muốn gọi hàm trước khi keyrelease. Và cũng có thể Ctrl + A sẽ không đánh dấu văn bản khi nhấn phím khi trả về sai.
Điều gì hiện kiểm soát + a làm trong trình duyệt của bạn? –
nó in văn bản ... nó không phá vỡ từ chức năng – Vishnu
'keydown' gây nên trước' keyup' phải không? –