我有一个我刚刚实现的下拉面板,需要在打开面板后将焦点保持在文本框中。文本框不在面板内,而是在网页面板的下方或下方。
这可能吗?如果可行,怎么办呢?我正在使用JQuery。
修改
要将焦点保留在此面板下方的文本框中,我将在此代码中添加$('#test').focus()
?
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:'visible'}).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);
答案 0 :(得分:0)
jquery .animate()
函数将回调方法作为其参数之一。动画完成后执行回调。您可以将代码插入到打开面板的动画的回调中,如下所示:
this.$mainpanel.animate({top: 0}, speed, function() { $('#test').focus(); }).attr({openstate: 'open'})