在展示之后将焦点设置为在div内锚定?

时间:2016-07-22 10:20:43

标签: javascript jquery html focus show-hide

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

我的代码:

<div class="nested-fields form-inline">
  <div class="form-group">
    <%= f.label :product, class: 'sr-only' %>
    <%= f.association :spree_product, collection: Spree::Product.for_select, as: :select, item_wrapper_class: 'form-control input-sm' %>
  </div>
    <%= link_to_remove_association "Remove", f, class: 'btn btn-danger btn-sm', data: cocoon_data_options %>
</div>

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

感谢您的尊敬。

1 个答案:

答案 0 :(得分:1)

其实正在工作!使用jquery 2.1.1

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

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

相关问题