jquery dialog 打开的时候自动聚焦解决方法

方法一:

p1_dialog_seniorSearch.dialog({  
    title:"高级查询",  
    autoOpen:false,//默认关闭  
    modal: true,//开启遮罩层  
    570,  
    height:330,  
    buttons: {  
        "查询":function(){  
            seniorSearch(1,20)  
        } ,  
        "关闭": function() {  
            p1_dialog_seniorSearch.dialog( "close" );  
        }  
    },  
    open:function(event, ui){  
        $(this).parent().focus();  
    }//取消获取焦点  
});  

方法二:

在要焦点的的控件加上 autofocus

如:第一个控件为 datepicker,默认dialog打开会自动弹出日历

解决:在该dialog加个隐藏input,

<input type="hidden" autofocus/>

未加 autofocus,dialog不会聚焦影藏的input的。

参考文章:

http://jqueryui.com/upgrade-guide/1.10/#added-ability-to-specify-which-element-to-focus-on-open

http://stackoverflow.com/questions/1202079/prevent-jquery-ui-dialog-from-setting-focus-to-first-textbox

原文地址:https://www.cnblogs.com/dscms/p/6094807.html