Home > Web Front-end > JS Tutorial > jQuery implements the method of setting focus in dialog_jquery

jQuery implements the method of setting focus in dialog_jquery

WBOY
Release: 2016-05-16 15:55:54
Original
1127 people have browsed it

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"); 
} 

Copy after login

Done! O(∩_∩)O..

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template