【问题标题】:how can i trigger event when hidden div get focus in jQuery?当隐藏的 div 在 jQuery 中获得焦点时如何触发事件?
【发布时间】:2010-09-30 05:06:58
【问题描述】:

在 tabb 设计中如果有多个隐藏的 div,当隐藏的 div 使用 jquery 获得焦点时,我如何触发事件。我尝试了“焦点”,但那是表单控件。请推荐

【问题讨论】:

  • 我只是好奇,但你为什么要在 hidden 元素上设置focus()
  • 隐藏元素不会得到focus

标签: javascript jquery events


【解决方案1】:

您可以为 show() 方法提供回调,前提是您是进行该调用的人。

$('#tab1').show('fast', function(){
    // do something now that it is showing
});

【讨论】:

    【解决方案2】:

    很难聚焦隐藏区域。但如果您现有的 DIV 代码是可编辑的,我建议使用不透明度作为替代方案。你可以这样做:

    HTML:

    <div id="hiddendiv" style="height:'200';width:'200'">This is hidden DIV</div>
    

    jQuery:

    $('#hiddendiv').stop().animate({ opacity: 0.0 }, 500);
    
    $('#hiddendiv').live('mouseenter', function(){
        $('#hiddendiv').stop().animate({ opacity: 1.0 }, 500);
    });
    

    Demo

    【讨论】:

      猜你喜欢
      • 2018-02-10
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 2014-06-09
      • 2016-05-20
      • 1970-01-01
      相关资源
      最近更新 更多