Unable to remove Autofocus in ui-dialog [duplicate]

喜你入骨 提交于 2019-11-29 17:27:08

问题


This question already has an answer here:

  • Prevent jQuery UI dialog from setting focus to first textbox 30 answers

The first element in my jQuery UI Dialog is an input, which when selected opens a datepicker...

How can I disable this input from being selected first?


回答1:


Add the following code before you call dialog. This will clear out the autofocus code. It works for me in jquery 2.0.3.

$.ui.dialog.prototype._focusTabbable = function(){};



回答2:


Very simple, just trigger the blur event on the input elements when the dialog box opens.

$("#dialog").dialog({
    open: function(event, ui) {
        $("input").blur();
    }
});

Check it out here

Solution with datepicker

NOTE: For more in-depth solution to this problem, read this answer too.




回答3:


JQuery sets the autofocus on the first input that is found.
So play it sneaky by creating a "fake" input at the first line of your dialog like that:

<input type='text' size='1' style='position:relative;top:-500px;' />

So your input will be out of the window and have the focus. Problem solved for me ;p



来源:https://stackoverflow.com/questions/9816299/unable-to-remove-autofocus-in-ui-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!