JQuery设置input自动获取焦点的方法非常简单,使用focus()方法即可。

但是如果在bootstrap模态框弹出时设置模态框中输入框获取焦点时,使用下面的代码是无效的:


$('#id').focus();
$('#modal').modal('show');

正确代码应该是:


$('#modal').on('shown.bs.modal', function () {
    $('#id').focus();
});
$('#modal').modal('show');
(adsbygoogle = window.adsbygoogle || []).push({});