Bootstrap模态 - 关闭时返回焦点&的tabindex = “ - 1”

时间:2015-09-01 15:49:00

标签: html twitter-bootstrap accessibility tabindex

我正在使用bootstrap模式来打开一个窗口,但是当窗口关闭时,焦点不会返回到打开它的链接,而是返回到容器,其中tabindex =“ - 1”。代码片段如下:

<div id=”main” tabindex=”-1”>
  <p>Main content goes here</p>
  <a href=”#”>a link in the main body</a>
</div>

我认为这是因为我在主要内容区域使用tabindex =“ - 1”作为跳过链接:

TRUNCATE TABLE TEST.dbo.SALARIES;
INSERT INTO TEST.dbo.SALARIES
  (PSA_SALARIE,PSA_LIBELLE,PSA_PRENOM,PSA_DATESORTIE)
    SELECT Matricule,Nom,Prenom,Date_sortie
      FROM  OPENROWSET(BULK 'E:\...\infoprofuniq.txt',
      FORMATFILE='E:\...\infoprof.fmt',
      FIRSTROW = 1,
      CODEPAGE = 'ACP'
) as t1 ;

有关如何克服此问题的任何帮助?

1 个答案:

答案 0 :(得分:0)

Use this:

$(document).on( "click", "[data-toggle='modal']", function() {
   var trigger = $(this)
   var modal = $( trigger.data("target") )

   // When bootstrap's modal "hidden" event fires, return focus to the trigger
   // Notice the binding is using $.fn.one as opposed to using $.fn.on
   modal.one("hidden.bs.modal", function() { trigger.focus() })
})

This will listen to any element with an attribute "data-toggle='modal' and return focus once the modal it controls closes.

This can be refined to a specific trigger by changing the delegation selector to:

$( "#myachor" ).on( "click", function() {..})

Bootstrap modal events docs