【发布时间】:2014-09-24 16:01:00
【问题描述】:
我正在尝试在模式显示后将焦点设置在输入上。
到目前为止我看到并尝试过的解决方案和链接:How to focus on a form input text field on page load using jQuery?、Jquery Focus on input field,但它们都不起作用。
我的代码其实很简单:
$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);
【问题讨论】:
-
我认为您必须等到动画完成才能聚焦输入。尝试增加
setTimeout中的等待时间 -
在显示模式后尝试获取输入 - jqueryui 可能会复制元素。
标签: javascript jquery jquery-ui