【发布时间】:2013-02-11 18:58:12
【问题描述】:
假设我在display: none; 中有很多 div,而只有第一个在visible。
在视图中,您可以按 ENTER 或 GO(在 iPad 中)浏览每个视图。所以想前进的时候,把当前的div改成none,下一个就改成visible。但是现在我还想将焦点设置在具有focusable 类的输入元素中。但它并没有设置焦点。
这是我的代码:
var setFocus = function () {
$("#question-container2").find("#question:visible").find('.focusable')[0].focus();
$("#question-container2").find("#question:visible").find('.focusable')[0].setSelectionRange(0, 0);
};
var nextPage = function () {
if ($currentPage < $totalPages) {
$currentPage++;
$("#question-container2").find("#question:visible").hide().next().show();
}
};
$(".input-area").keypress(function (e) {
if (e.keyCode == 13) {
// Do something
nextPage();
setFocus();
return false;
}
});
【问题讨论】:
标签: javascript jquery html css ipad