The example in this article describes how jQuery implements dialog setting focus. Share it with everyone for your reference. The specific analysis is as follows:
When a dialog box pops up, by default we should focus on the input text box, but writing $("#txtGroupName").focus(); before dialog.show() will not take effect.
After checking the official documentation of jQuery, I found that dialog provides a focus parameter, ok, try it first~~
//显示新建项目群组对话框 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: { "保存": function() { var name = el("txtGroupName").value; var description = el("txtDescription").value; var b = $("#fgroup").valid(); if (b) { createGroupJson(); closeCreateGroupDialog(); } else { showError(lmslang.formValidate_Error); } } , "取消": function() { closeCreateGroupDialog(); } } }); } //隐藏新建项目群组对话框 function closeCreateGroupDialog(){ $("#layout-createProjectGroup-pane").dialog("close"); }
Done! O(∩_∩)O..
I hope this article will be helpful to everyone’s jQuery programming.