使用js 設定組合快速鍵

來源:互聯網
上載者:User

標籤:

使用js 設定組合快速鍵

  使用js設定快速鍵的本質就是獲得你要設定的這個鍵的keyCode 的值,如果要加ctrl,alt,shift,那麼就添加一個ctrlkey,altKey,shiftKey來判斷下,所以關鍵在於擷取keycode的值。

  (1) 設定 ctrl +enter 提交  

1 if (e.ctrlKey && e.keyCode == 13){  2    return submit();  3 }

  (2) 設定  Alt+ 方向鍵 ←提交

1 if (e.altKey&& e.keyCode == 37){  2     return submit(); 3 }

  (3) 設定  shift+F10 提交

1 if (e.shiftKey&& e.keyCode == 37){   2    return submit();3 4 }

  (4) 設定enter 提交

1 if (e.keyCode == 13){2  return submit();   3 }

  一些常見的快速鍵的KeyCode:

1 keycode    8 = BackSpace BackSpace 2   keycode    9 = Tab Tab 3   keycode   12 = Clear 4   keycode   13 = Enter 5   keycode   16 = Shift_L 6   keycode   17 = Control_L 7   keycode   18 = Alt_L 8   keycode   19 = Pause 9   keycode   20 = Caps_Lock10   keycode   27 = Escape Escape11   keycode   32 = space space12   keycode   33 = Prior13   keycode   34 = Next14   keycode   35 = End15   keycode   36 = Home16   keycode   37 = Left17   keycode   38 = Up18   keycode   39 = Right19   keycode   40 = Down20   keycode   41 = Select21   keycode   42 = Print22   keycode   43 = Execute23   keycode   45 = Insert24   keycode   46 = Delete25   keycode   47 = Help

<script type="text/javascript">

//當onkeydown 事件發生時調用hotkey函數
        $("#CarNo").keydown(function (e) {
            if (e.keyCode == 13)
            {
               alert("你按了鍵盤ENTER.");
            }
        });

</script>

使用js 設定組合快速鍵

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.