JQuery Dialog Open Autofocus solution (two methods) _jquery

Source: Internet
Author: User

Here are two ways to solve the problem of automatic focus when jquery Dialog open. The concrete realization method Everybody may refer to this article.

Method One:

P1_dialog_seniorsearch.dialog ({ 
title: "Advanced Query", 
autoopen:false,//default close 
modal:true,//Open mask layer 
width : 570, 
height:330, 
buttons: { 
query: function () { 
seniorsearch (1,20) 
}, 
close: function () { 
p1_dialog_seniorsearch.dialog (' close '); 
} 
, 
open:function (event, UI) { 
$ (this). Parent (). focus (); 
Cancel get Focus 
});

Method Two:

Add autofocus to the control that you want to focus on

Such as: The first control is DatePicker, the default dialog open automatically pop-up calendar

Solution: Add a hidden input in the dialog,

<input type= "hidden" autofocus/>

No added Autofocus,dialog will not focus on the shadow of the input.

Ps:jquery dialog automatically focus on the first control when it is opened

In the project, the use of JQuery dialog, in dialog ("open") a page, the focus will automatically focus on the first control, just this control binding datepicker, the calendar automatically bounced out, tangled half-day fruitless, Google a bit, The same problem has been encountered. Give the solution first

<input Autofocus> adds a autofocus attribute to the label to give the specified control the focus. For example, the first is a date control, then add this attribute to other tags, the first calendar control will not focus, and will not bounce out. In other words, this method is a bit like a decoy.

A URL to address the problem is attached:

Http://stackoverflow.com/questions/1202079/prevent-jquery-ui-dialog-from-setting-focus-to-first-textbox

http://jqueryui.com/upgrade-guide/1.10/

The above is a small set to introduce the jquery Dialog open when the automatic focus of the solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.