jquery ui datepicker给予焦点的输入,而不是在IE中再次加载日历? [英] jquery ui datepicker give focus to the input without loading the calendar again in IE?

查看:103
本文介绍了jquery ui datepicker给予焦点的输入,而不是在IE中再次加载日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如果用鼠标选择日期,jquery ui datepicker会丢失焦点。我想能够把重点放在这个输入领域。所以我做了这样的

I know that jquery ui datepicker loses focus if the date is selected with a mouse. I want to able to give focus to that input field. So i did something like this

    $("#patientDob").live("click", function() {
              $("#patientDob").datepicker({
            onSelect: function() {
this.focus();
// selecting a date moves the page, so remove the href attribute
$(".ui-datepicker a").removeAttr("href");
        },  

                        changeMonth: true,
                        changeYear: true,
                        duration: 'fast',
                        showOn: 'focus' 
    }).focus();
});

这确实给出了输入字段的重点,但是在IE中它会继续加载日历。它不会在Firefox或chrome中这样做。如何在IE中一次又一次地加载日历就可以将焦点放在输入域?

This does gives the focus to the input field, but in IE it keeps on loading the calendar again. It does not do that in firefox or chrome. How can i be able to give focus to the input field without loading the calendar again and again in IE?

另外,如果我自己做一个输入字段,并且在IE中选择日期后,该字段失去焦点,如果我尝试按退格键,则将我带到之前访问过的页面。
任何帮助是赞赏!

Also, if i make a input field readonly and after selecting the date in IE the field loses focus and if i try to press backspace it takes me to the previously visited page. any help is appreciated!

推荐答案

我的解决方案使用beforeShow事件取消IE的显示(因为似乎在Chrome和Firefox中没有黑客就可以正常工作)。在将焦点返回到输入框之前,onSelect和onClose设置一个标志。看到我完整的写了还发送模糊并且更改事件,如果需要的话。

My solution uses the beforeShow event to cancel the show for IE (since it seems to work okay without the hack in Chrome and Firefox). The onSelect and onClose set a flag before returning focus to the input box. See my full write-up to also send blur and change events if you need those.

$("input.dateInput").datepicker({            
   /* fix buggy IE focus functionality */
   fixFocusIE: false,

   onSelect: function(dateText, inst) {
       this.fixFocusIE = true;
       $(this).focus();
   },
   onClose: function(dateText, inst) {
       this.fixFocusIE = true;
       this.focus();
   },
   beforeShow: function(input, inst) {
       var result = $.browser.msie ? !this.fixFocusIE : true;
       this.fixFocusIE = false;
       return result;
   }
});

这篇关于jquery ui datepicker给予焦点的输入,而不是在IE中再次加载日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆