Javascript 从 jquery 对话框中的输入字段中删除焦点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4276686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:41:30  来源:igfitidea点击:

Remove focus from an input field in a jquery dialog

javascripthtml

提问by Alok Swain

I have a button onclick of which a jquery dialog appears with two input fields which are jquery datepickers. Whenever the dialog appears, the first fields gets focus automatically, hence the datepicker pops up. I have resolved this for now by adding another dummy input field. Is there a better way ?

我有一个按钮 onclick,其中出现一个 jquery 对话框,其中包含两个输入字段,它们是 jquery 日期选择器。每当对话框出现时,第一个字段会自动获得焦点,因此会弹出日期选择器。我现在已经通过添加另一个虚拟输入字段解决了这个问题。有没有更好的办法 ?

Sorry if the question is repeated. I tried searching for one already existing but couldn't get one. Please point me to an existing question if present.

对不起,如果问题重复。我试图寻找一个已经存在的,但无法得到一个。如果存在,请指出一个现有问题。

Edit:

编辑:

Okay my code goes as follows. onClick of a button the jdialog appears and there are 2 datepicker input fields inside the div "select_date_dialog".

好的,我的代码如下。点击一个按钮,jdialog 出现,div“select_date_dialog”中有 2 个日期选择器输入字段。

$("#select_date").click(function(){
    $("#select_date_dialog").dialog({
        modal: true,
        dialogClass: 'connect-dialog',
        height: 100,
        width: 500
    });
});

afaik: can you be a bit more specific how blur will help me ? I tried adding this as suggested.

afaik:你能具体点说一下模糊对我有什么帮助吗?我尝试按照建议添加此内容。

open: function(event, ui) {
                $('#custom_from_date').blur();
            }

blur happens when there input field loses focus. can i use blur to specify whether that field should get focus or not ?

当输入字段失去焦点时会发生模糊。我可以使用模糊来指定该字段是否应该获得焦点吗?

回答by Mark Bell

You could create a handler for the dialog's openevent and blur the field in that:

您可以为对话框的open事件创建一个处理程序并在其中模糊字段:

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

I'd need to see more of your code to be any more specific though.

不过,我需要查看更多代码才能更具体。