加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

模态对话框 – Bootstrap Modal Focus无法正常工作

发布时间:2020-12-18 00:24:09 所属栏目:安全 来源:网络整理
导读:在制作网络时,我没有把注意力集中在Bootstrap Modal的“输入”中,我尝试了一切并且没有工作,模态出现但是输入没有得到焦点.我用一个简单的模态做了一个“test.php”,也没用.这是“test.php” html lang="es"head meta charset="utf-8" meta http-equiv="X-UA
在制作网络时,我没有把注意力集中在Bootstrap Modal的“输入”中,我尝试了一切并且没有工作,模态出现但是输入没有得到焦点.我用一个简单的模态做了一个“test.php”,也没用.这是“test.php”
<html lang="es">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">


    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <script src="../js/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js">



    <script>


$('#myModal').on('shown.bs.modal',function () {
    $('#referencia').focus();
})


    </script>

</head>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <input name="referencia" id="referencia" type="text" class="form-control text-uppercase" placeholder="Descripci&oacute;n">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>

如果我在我的服务器上尝试此代码它不起作用,在unelink.es服务器也不工作,但如果我把相同的代码放在“小提琴”,工作正常.

什么是错的?如果我需要别的东西……或者在服务器上安装一些东西.

P.D.对不起我的英语不好.

解决方法

试试这个(自动对焦添加到您的链接):
<input name="referencia" id="referencia" type="text" class="form-control text-uppercase" placeholder="Descripci&oacute;n" autofocus>

或试试这个:

$('#myModal').on('shown.bs.modal',function () {
    $('#myInput').focus();
})

或这个:

// Every time a modal is shown,if it has an autofocus element,focus on it.
$('.modal').on('shown.bs.modal',function() {
  $(this).find('[autofocus]').focus();
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读