首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用BootStrap键打开ShortCut模式弹出

如何使用BootStrap键打开ShortCut模式弹出
EN

Stack Overflow用户
提问于 2013-05-15 10:54:28
回答 2查看 6.5K关注 0票数 3

我在我的项目中使用了Twitter Bootstrap模式弹出对话框;

代码语言:javascript
复制
// when this button is click, the dialog is open    
<a type="button" class="btn" style="width:100%;" href="#test_modal" data-toggle="modal">Add Image</a>

如您所见,当单击上面的按钮时,它打开下面的对话框;

代码语言:javascript
复制
<div class="modal fade" id="test_modal">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h3>Modal Header</h3>
  </div>
  <div class="modal-body">
    <p>Test Modal</p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Close</a>
    <a href="#" class="btn btn-primary">Save Changes</a>
  </div>
</div>

但是,我想为它分配一个快捷键。例如,当有人按下Ctrl+Shift+L**,时,我想打开上面的对话框。我不需要按下按钮。**

如何在jQuery中实现上述功能?

EN

回答 2

Stack Overflow用户

发布于 2018-09-04 08:06:04

尝试以下操作:单击ctrl+m;当单击ctrl+m显示模式时。

代码语言:javascript
复制
$(document).on('keydown', function ( e ) {
    // You may replace `m` with whatever key you want
    if ((e.metaKey || e.ctrlKey) && ( String.fromCharCode(e.which).toLowerCase() === 'm') ) {
		$("#exampleModal").modal('show');
    }
});
代码语言:javascript
复制
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />

    <link rel="stylesheet" media="print" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

票数 3
EN

Stack Overflow用户

发布于 2013-05-15 11:03:43

你可以这样做

代码语言:javascript
复制
$(document).keydown(function(evt){
    if (evt.keyCode==108 && (evt.ctrlKey) && (evt.shiftKey)){
        evt.preventDefault();
        $('#yourModal').modal('show');
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16563192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档