如何在模态中设置对输入的关注
How to set focus on input in modal?
我正试图在模态显示后将重点放在输入上。
到目前为止,我看到并尝试过的解决方案和链接:如何使用jQuery在页面加载时关注表单输入文本字段?,Jquery专注于输入字段,但它们都不起作用。
我的代码其实很简单:
$input = $("#letter-change-text").find("input[type='text']");
$input.val($.trim("I am just testing!!"));
$("#letter-change-text").modal('show');
$input.focus(); // this should focus the textbox in order to allow immediately input by the user
您可以在JSfiddle中查看此问题。
我也尝试过,但没有成功:
setTimeout(function(){
$input.focus();
}, 0);
使用显示的事件
$(function(){
$input = $("#letter-change-text").find("input[type='text']");
$input.val($.trim("I am just testing!!"));
$('#letter-change-text').on('shown.bs.modal', function (e) {
$input.focus();
}).modal('show');
});
您可以尝试
$("#dgRejectSalvage").on('shown.bs.modal', function () {
$(this).find('#RejectionReason').focus();
});
相关文章:
- Angular指令中的最佳实践是将文本输入设置为英尺和英寸的格式
- 如何使用ian:accounts-ui-botstrap-3根据Meteor中的用户输入设置配置文件字段值
- 使用JS将输入设置为只读
- 正在为禁用的输入设置标题属性
- 用户输入设置数组长度
- 如何使用来自@Html.TextBoxFor的用户输入设置@Html.RadioButtonFor的值
- 根据其他输入设置最大值
- PHP论坛建设,输入设置栏(粗体,..链接等),如何申请
- 为输入设置最大值时出现插值错误
- jQuery MaskMoney - 将输入设置为字段的开头
- 在 Javascript 中将文本输入设置为变量
- (联合国)通过字符串输入设置嵌套数组值
- 将类型为数字的输入设置为字符串
- jQuery UI Slider(从文本输入设置)
- 根据第一个询问的输入设置输入类型范围的最小值
- 如何通过JavaScript将HTML5输入设置为必需
- 根据用户在Javascript中的输入设置Date()对象的正确方法是什么
- 如何在没有提交按钮AngularJS的情况下将所有输入设置为$touch
- angularjs将默认日期输入设置为今天
- 如何将用户尝试填充数据的输入旁边的所有输入设置为只读