JavaScript uses focus () to set focused failure resolution _javascript tips

Source: Internet
Author: User

Yesterday modified the EPG page above the set-top box, encountered a small problem. Users need to buy the game pop-up Purchase confirmation dialog box, the default focus of the dialog box must stay on the "Cancel" button. Very simple requirements, the focus () method of using JavaScript can be implemented. A simple code example is as follows:

document.getElementById ("Cancel"). Focus ()

But the hard drive is that the set-top box is really a big pit. To be compatible with all existing set-top box models, 8 set-top boxes need to be fitted. And then there's the problem! A ZTE B600 set-top box is completely unable to focus on the cancellation button. The following is my solution:

First verify that the set-top box supports the getElementById () method and that the element with the id "Cancel" was successfully obtained: The test method is simple, and a <p id= "test" >test</p> is written directly. Then get the element with the ID "test" in the same place and do a simple operation document.getElementById ("test"). Innerhtml= "Hello"
Finally, "Try...catch (E) ..." was used to capture the cause of "focus ()" failure

Try () { 
<span style= "White-space:pre" > </span>document.getelementbyid ("Cancel"). Focus () 
} catch (e) { 
<span style= "White-space:pre" > </span>alert (e.name + ":" + e.what ()); 
}

But it's just weird! The results of both of these steps indicate that the set-top box supports focus () and getElementById (), but that it is not possible to set focused to a pop-up dialog box.

After tossing one hours, the last big boss appeared, simply said a word to solve the problem! It is possible to actively invoke Flur () to cancel the original focus!

document.getElementById ("Purchase"). Flur ()

Then it solves the problem. Have to feel! In the process of solving this problem, their own thinking is actually quite correct, but the knowledge is clearly not enough. The gap between general programmers and senior programmers in addition to solving the problem of thinking, there are experience and knowledge gap!

Related Article

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.