Home > Web Front-end > JS Tutorial > Perfectly solve the problem that input cannot get focus when BootStrap modal box and select2 are used together.

Perfectly solve the problem that input cannot get focus when BootStrap modal box and select2 are used together.

巴扎黑
Release: 2017-09-02 13:32:43
Original
3121 people have browsed it

Using the select2 plug-in in the bootstrap modal box will cause the input box in select2 to be unable to gain focus and input. How to solve this problem? The editor below brings you a solution to the problem that the input cannot gain focus when the BootStrap modal box and select2 are used together. Let’s take a look.

Using the select2 plug-in in the bootstrap modal box will cause select2 to The input input box cannot gain focus and cannot input.

Solution:

Change the tabindex="- 1" Delete (test successful):


<p id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <p class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  <h3 id="myModalLabel">Panel</h3>
 </p>
<p class="modal-body" style="max-height: 800px">
<p id="myModal" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <p class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  <h3 id="myModalLabel">Panel</h3>
 </p>
<p class="modal-body" style="max-height: 800px">
Copy after login

can be processed in the onshow method. The main principle is because bootstrap's tabindex='-1 ', occupies the tabindex='0' of select2. After the script processes the modal box and displays it, delete the tabindex attribute of the modal box


BootstrapDialog.show({
   onshown: function (dialogRef) {
    $("#"+dialogRef.getId()).removeAttr("tabindex");
  }
})
Copy after login

Rewrite the enforceFocus method (tested to have no effect):


$.fn.modal.Constructor.prototype.enforceFocus = function() {};
Copy after login

The above is the detailed content of Perfectly solve the problem that input cannot get focus when BootStrap modal box and select2 are used together.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template