How to Set focus in dialog using jQuery
This example describes how jQuery implements dialog to set focus. Share it with you for your reference. The specific analysis is as follows:
When the dialog box is displayed, the focus should be directed to the input text box by default, but $ ("# txtGroupName"). focus () is written before dialog. show (); does not take effect.
Check jQuery's official documentation and find that dialog provides a focus parameter. OK. Try ~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
// The Create Project Group dialog box is displayed. Function showCreateProjectGroupDialog (I ){ $ ("# Layout-createProjectGroup-pane"). show (). dialog ({ Modal: true , Title: lmslang. listProjectGroup_Create , Width: 450 , Overlay :{ Opacity: 0.5 } , Focus: function (ev, data ){ $ ("# TxtGroupName"). focus (); } , Buttons :{ "Save": function (){ Var name = el ("txtGroupName"). value; Var description = el ("txtDescription"). value; Var B = $ ("# fgroup"). valid (); If (B ){ CreateGroupJson (); CloseCreateGroupDialog (); } Else { ShowError (lmslang. formValidate_Error ); } } , "Cancel": function (){ CloseCreateGroupDialog (); } } }); } // Hide the new project group dialog box Function closeCreateGroupDialog (){ $ ("# Layout-createProjectGroup-pane"). dialog ("close "); } |
Done! O (partition _ partition) O ..
I hope this article will help you with jQuery programming.