jQuery Facebox plugin: Focus the popup appearance

强颜欢笑 提交于 2019-12-14 02:35:22

问题


I have an HTML page with facebox popup.

This page contains many links and forms, and the popup contains one form. What I want is, when I open the popup, using only keyboard's buttons, to go directly to the form's inputs of the popup with 'tab' button.

Here is a fiddle --> http://jsfiddle.net/tk1jagpb/

$(document).ready(function () {
  $('a[rel*=facebox]').facebox()
})
.popup {
  background-color: mistyrose;
}
<p><a href="#info" rel="facebox">Click to display</a></p>

<div id="info" style="display: none;">
  <p>Popup div</p>
  <p><input type="text" value = "" /></p>
  <p><input type="text" value = "" /></p>
  <p><input type="text" value = "" /></p>
  <p><input type="text" value = "" /></p>
</div>

<p><input type="text" value = "" /></p>
<p><input type="text" value = "" /></p>
<p><input type="text" value = "" /></p>

If it were so, I might use the keyboard without having to click the popup box... It would save my time.

Thanks.


回答1:


You can listen for the 'reveal.facebox' event which is fired just after the facebox is shown. Once the facebox is shown, just focus the first input field.

$(document).ready(function() {
    $('a[rel*=facebox]').facebox();
    $(document).bind('reveal.facebox', function() {
        $('.popup input:first').focus();
    });
})


来源:https://stackoverflow.com/questions/29542023/jquery-facebox-plugin-focus-the-popup-appearance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!