简体   繁体   中英

Remove focus from an input field in a jquery dialog

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 ?

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".

$("#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.

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 ?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM