A quick solution to onclick and onblur conflicts: onclickonblur conflicts

Source: Internet
Author: User

A quick solution to onclick and onblur conflicts: onclickonblur conflicts

There is an ajax drop-down box in the search box on the Sina homepage. We need to implement an item in the drop-down box to change the value in the search box to this item. At the same time, the drop-down box disappears, but the drop-down box also disappears when you click somewhere else. Rough


We also use onblur and onclick to hide the drop-down box, but the bigger problem arises. These two functions conflict. onblur is too powerful and there is no chance to implement the onclick method, the content of the clicked item cannot be obtained in the search box. This is the conflict between onclick and onblur.

For this problem, we will introduce two solutions:

1. use setTimeout to postpone onblur execution, so that onblur can be executed after onclick execution. (The setTimeout time should be set to more than ms, otherwise it will still not work.) The sample code is as follows:

<! DOCTYPE html> 

2. Use document. onmousedown to hide the drop-down box instead of onblur.

<! DOCTYPE html> 

The quick solution to the conflict between onclick and onblur is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.

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.