IE8 focus Failure Solutions

These days two met failure in IE8 under focus very strange question, of course, this refers to JS function:. Document.getElementById ( "id") focus (); or $ ( "# id") focus (). ;

One problem: the landlord is in ifram the page, click on the Save button in the ifram will be redirected to this page, and the focus will be given to the first text box in domcument.ready (). The strange thing is, the first time you open this page is no problem, and so after this click Save redirect page, IE8 low version (ie8 8.0.7600.16385), the cursor can not be positioned on the first text box, write the landlord deliberately a function, upon entering the focus, the background color of the text box into another color, the background color changed results, but no focus. Finally lazily somehow solved. setTimeout ( "$ ( '# id') focus ();.", 500);

 

Second problem: the landlord is still in ifram page, after page, click a button, it will pop up a layer of dynamically generated data layer, when the pop-up layer, the first text box has focus (all dynamically generated the first text box id is the same). The result has a problem in ie8 in the. Sometimes gets the focus, and sometimes can not get the focus, really boring endless. Later it was found that about two to solve the problem:

1. Each time the hidden layer, data deletion layer: $ ( "# id") empty ();.

Using this method $ ( "# id"). Show ( 'fast', function () {layer 2. When the popup

"$('#txt1').focus();

});

The main reason may be IE8 resolve a problem that may locate to a txt1 before, and there may not generate txt1, focus on the first execution of the function. Resulting in no focus.

 

Currently landlord wonderful variety of problems found in the IE 8. Egg really hurt for a long time.

 

Reproduced in: https: //www.cnblogs.com/xinjian/p/3771307.html

Guess you like

Origin blog.csdn.net/weixin_33834910/article/details/93822278