开发者

Help with onblur

开发者 https://www.devze.com 2023-01-22 19:53 出处:网络
I have a dropdown panel that I have just implemented and need to keep the focus in a textbox after I open the panel. The textbox is not inside the panel but rather below or off the panel on the web pa

I have a dropdown panel that I have just implemented and need to keep the focus in a textbox after I open the panel. The textbox is not inside the panel but rather below or off the panel on the web page.

Is this possible and if so, how can it be done? I'm using JQuery.

EDIT: To keep the focus in the textbox below this panel, where would I add $('#test').focus() in this code?


var jkpanel={
  controltext: '',
  $mainpanel: null, contentdivheight: 0,

  openclose:function($, speed){
    this.$mainpanel.stop() //stop any animation
    if (this.$mainpanel.attr('openstate')=='closed')
      this.$mainpanel.animate({top: 0}, speed).attr({openstate: 'open'})
    else
      this.$mainpanel.animate({top: -this.contentdivheight+'px'}, speed).attr({openstate: 'closed'})
  },

  init:function(file, height, speed){
    jQuery(document).ready(function($){
      jkpanel.$mainpanel=$('<div id="dropdownpanel"><div class="contentdiv"></div><div class="control">'+jkpanel.controltext+'</div></div>').prependTo('body')
      var $contentdiv=jkpanel.$mainpanel.find('.contentdiv')
      var $controldiv=jkpanel.$mainpanel.find('.control').css({cursor: 'wait'})
      $contentdiv.load(file, '', function($){
        var heightattr=isNaN(parseInt(height)) ? 'auto' : parseInt(height)+'px'
        $contentdiv.css({height: heightattr})
        jkpanel.contentdivheight=parseInt($contentdiv.get(0).offsetHeight)
        jkpanel.$mainpanel.css({top:-jkpanel.contentdivheight+'px', visibility:'v开发者_运维百科isible'}).attr('openstate', 'closed')
        $controldiv.css({cursor:'hand', cursor:'pointer'})
      })
      jkpanel.$mainpanel.click(function(){jkpanel.openclose($, speed)})
    })
  }
}

//Initialize script: jkpanel.init('path_to_content_file', 'height of content DIV in px', animation_duration)
jkpanel.init('panelcontent.htm', '200px', 500);


The jquery .animate() function takes a callback method as one of its arguments. The callback executes after the animation completes. You could insert your code as the callback to the animation that opens the panel, like so:

this.$mainpanel.animate({top: 0}, speed, function() { $('#test').focus(); }).attr({openstate: 'open'})
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号