选择日期后,避免重新打开日期选择器

Web*_*man 12 javascript jquery internet-explorer jquery-ui datepicker

仅在IE中使用此代码

$('#datepicker').datepicker({
    onSelect : function(x, u){
     $(this).focus();   
    }
});
Run Code Online (Sandbox Code Playgroud)

当我选择一个日期时,日期选择器重新打开,因为我加入$(this).focus();onSelect.我该如何解决这个问题?(例子)

我正在使用jquery 1.8.2和jquery-ui 1.9

lha*_*han 12

我今天遇到了这个问题,并为我提供了不同的解决方案.我的场景是我的DatePicker在jQuery UI Dialog弹出窗口内.在Chrome中一切正常,但在IE中,日历会在选择日期后重新出现.

事实证明,jQuery 1.10.1中存在一个漏洞:http://bugs.jqueryui.com/ticket/9125

还有一个链接到的JSFiddle演示了IE中的错误.有两种方法可以在IE中使用它:

  1. 设置modalfalse
  2. 在选择日期后立即关注另一个元素

我选择#2,这是一个修复示例(只是更新JSFiddle代码):

标记:

<div id="dialog">
    <input id="datepicker" />
    <input type='button' value='save' id='btnSave'/>    
</div>
Run Code Online (Sandbox Code Playgroud)

JS:

$( "#datepicker" ).datepicker({onSelect: function() { $('#btnSave').focus(); }});
$( "#dialog" ).dialog({ modal: true });
Run Code Online (Sandbox Code Playgroud)

希望这有助于未来的人!


A. *_*lff 9

这是我能得到的最好的解决方法:

(灵感来自此链接)

的jsfiddle

$('#datepicker').datepicker({
            /* fix buggy IE focus functionality */
            fixFocusIE: false,    
            onSelect: function(dateText, inst) {
                  this.fixFocusIE = true;
                        $(this).change().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;
            }
}).click(function(){$(this).focus()});
Run Code Online (Sandbox Code Playgroud)

请注意,正如您在问题中所建议的那样,即时通讯使用jquery-UI 1.9.0.在您的示例中,您使用的是jquery-ui 1.8.15,它已知在某些事件上有错误(例如IE上的beforeShow()).

  • 这不适用于IE中的jQuery> 1.9 <= 9 http://jsfiddle.net/hv77F/22/互联网需要一个解决方案,如果有人有足够的时间捐赠给一个有价值的事业! (2认同)

elb*_*for 5

我在IE中使用它,它也会停止重新打开datepicker

JQuery的:

        onSelect: function(){ 
        $("#focusfix").focus();
    },
Run Code Online (Sandbox Code Playgroud)

HTML(对话框div的第一行):

<input class="ui-helper-hidden-accessible" id="focusfix" type="text"autofocus/>
Run Code Online (Sandbox Code Playgroud)