【问题标题】:How can I slideToggle an input and autofocus at the same time?如何同时滑动切换输入和自动对焦?
【发布时间】:2015-10-09 14:31:19
【问题描述】:

我正在尝试在 onClick 上滑动切换隐藏的 div 并自动聚焦输入。

我试过这个,我也试过 $( ".search-input" ).focus();和 $(this).find('input[type="text"]').focus();似乎都不起作用。

我在这里错过了什么......?

$( ".search" ).click(function() {
  $( ".search-input" ).slideToggle();
  $(this).find('input[type="text"]').focus();
});

这是一个小提琴https://jsfiddle.net/odu7ckzh/

欢迎提出建议:)谢谢

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    只需将.focus() 链接到.slideToggle()

    $( ".search" ).click(function() {
      $( ".search-input" ).slideToggle().focus();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      • 2017-06-05
      相关资源
      最近更新 更多