【问题标题】:Setting focus to anchor inside div after show?显示后将焦点设置在 div 内?
【发布时间】:2016-07-22 10:20:42
【问题描述】:

我正在尝试将焦点设置到隐藏 div 元素内的锚元素,同时单击另一个锚链接。我尝试了几个选项,例如 .focus()、.focusin()。但没有任何效果。

我的代码:

    <script>
    $(document).ready(function(){
        $("#clickShow").on('click', function(){
            $("#showDescription").show();
            $("#showDescription").find("a").focus();
        });
    });
</script>
<div>
    <a href="#" id="clickShow">View Hidden Text</a>
</div>

<div id="showDescription" style="display:none;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap <a href="#">Link Text</a> into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>

我想知道,我在这里缺少什么来完成它?

感谢您的宝贵帮助。

【问题讨论】:

    标签: javascript jquery html focus show-hide


    【解决方案1】:

    实际上它的工作!使用 jquery 2.1.1

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#clickShow").on('click', function(){
                $("#showDescription").show();
                $("#showDescription").find("a").focus();
            });
        });
    </script>
    <div>
        <a href="#" id="clickShow">View Hidden Text</a>
    </div>
    
    <div id="showDescription" style="display:none;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap <a href="http://www.google.com">Link Text</a> into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>

    编辑:也在 1.11.1 中尝试过......它的工作...... 也许你的问题是别的

    【讨论】:

    • 其实我的应用程序使用的是 jQuery 1.11.1 版本。是否有任何可能性可以使它成为一个功能性的。
    • 在 1.11.1 中也尝试过......它的工作原理......也许你的问题是别的东西
    猜你喜欢
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 2016-12-06
    • 2011-10-08
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多