Model view controller 想要自动对焦OK按钮的引导模式
我有一个情态动词。有一个OK按钮。我想把焦点放在按钮上。我试过自动对焦,但它对焦了一秒钟后就消失了 _Layout.cshtml中的代码是:Model view controller 想要自动对焦OK按钮的引导模式,model-view-controller,less,bootstrap-modal,Model View Controller,Less,Bootstrap Modal,我有一个情态动词。有一个OK按钮。我想把焦点放在按钮上。我试过自动对焦,但它对焦了一秒钟后就消失了 _Layout.cshtml中的代码是: <!-- modal that can notify users of errors --> <div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal" aria-hidden="true">
<!-- modal that can notify users of errors -->
<div id="error-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="error-modal" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">Notice</h4>
</div>
<div class="modal-body">
<ul>
<!-- ko foreach: ModalErrors -->
<li data-bind="text: $data"></li>
<!-- /ko -->
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
您可以使用此js代码来实现这一点:
modal = $("#error-modal");
modal.find('.btn-primary').focus();
此代码将需要jQuery如果使用bootstrap 3,您可以在模态显示在屏幕上后通过挂接模态显示事件来聚焦元素:
$('.modal').on('shown.bs.modal', function (e) {
// do something...
});
请参见我必须在我的按钮类型中添加id=“ok notice button”…使用javascript,然后:
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
</div>
$("#error-modal").on('shown.bs.modal', function (event) {
$("#ok-notice-button").focus();
});
好啊
$(“#错误模式”).on('show.bs.modal',函数(事件){
$(“#确定通知按钮”).focus();
});
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
</div>
$("#error-modal").on('shown.bs.modal', function (event) {
$("#ok-notice-button").focus();
});