Bootstrap 模态焦点不工作
Bootstrap Modal Focus not working
在制作网络时,我没有在 "input" 中获得焦点到 Bootstrap 模式,我尝试了所有方法但没有成功,模式出现但输入没有获得焦点。我用一个简单的模式制作了一个 "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">×</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ó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 服务器上也不起作用,但如果我将相同的代码放在 "fiddle" 上,则工作正常。
知道哪里出了问题吗?如果我需要其他东西...或在服务器中安装一些东西。
P.D。对不起我的英语。
试试这个(自动对焦添加到您的 link):
<input name="referencia" id="referencia" type="text" class="form-control text-uppercase" placeholder="Descripció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();
});
试试这个:
$('#modal_id').modal('show').on('shown.bs.modal', function() {
$('input_element_id').focus();
});
或者试试这个:
$('#modal_id').on('shown.bs.modal', function() {
$('input_element_id').focus();
});
$('#modal_id').modal('show');
在制作网络时,我没有在 "input" 中获得焦点到 Bootstrap 模式,我尝试了所有方法但没有成功,模式出现但输入没有获得焦点。我用一个简单的模式制作了一个 "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">×</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ó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 服务器上也不起作用,但如果我将相同的代码放在 "fiddle" 上,则工作正常。
知道哪里出了问题吗?如果我需要其他东西...或在服务器中安装一些东西。
P.D。对不起我的英语。
试试这个(自动对焦添加到您的 link):
<input name="referencia" id="referencia" type="text" class="form-control text-uppercase" placeholder="Descripció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();
});
试试这个:
$('#modal_id').modal('show').on('shown.bs.modal', function() {
$('input_element_id').focus();
});
或者试试这个:
$('#modal_id').on('shown.bs.modal', function() {
$('input_element_id').focus();
});
$('#modal_id').modal('show');