javascript - 为什么当我在 iPad 中按下 GO 时,没有聚焦下一个输入?

标签 javascript jquery html css ipad

假设我在 display: none; 中有很多 div,而只有第一个在 visible 中。

在 View 中,您可以按 ENTER 或 GO(在 iPad 中)浏览每个 View 。所以想前进的时候,把当前的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;
    }
});

最佳答案

在您的元素中指定一个制表符索引。这是一个浏览器可访问性属性,它将告诉浏览器在您完成当前字段后导航到下一个位置。

参见:http://reference.sitepoint.com/html/a/tabindex

关于javascript - 为什么当我在 iPad 中按下 GO 时,没有聚焦下一个输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14818959/

相关文章:

javascript - 更好的做法 : Eliminate the nested loops?

javascript - JQuery 从嵌套标签中抓取内容

jquery - 在 Owl Carousel 图像上添加背景颜色

javascript - 从新创建的元素中删除事件

html - <table> 上的垂直对齐稍微偏离中心......知道为什么吗?

javascript - 禁用浏览器缓存

javascript - TypeScript 在这个范围内出错

javascript - 获取浏览器中所有现有内置变量的完整列表

jquery - jqgrid addrowdata问题

javascript - 为什么我的 HTML 页面会重新绘制,替换我的输入?