Chrome determines whether to click the label on the input to implement other labels. chromeinput

Source: Internet
Author: User

Chrome determines whether to click the label on the input to implement other labels. chromeinput

Function to be implemented: when the input box is out of focus and the key is not cleared, run the reset method to reset the input style. When you click the clear key, run the clear method to clear the input content.

The following code is intended for implementation:

$ (". Search-input"). focusout (function () {if (document. activeElement. className! = 'Close-t') {// close-t indicates the name of the clearing key class $ ('. search-input '). addClass ('search-before'); values ('.close').css ('display', 'None'); document. getElementById ('search '). value = '';}});

When the inpu box is out of focus, the first thing that gets the focus is the body tag. Because of this, the method fails and the following code is used to implement this function.

$ ("# Search "). focusout (function () {// check whether the Clear button is clicked after the focal loss. If yes, var tapCloseButton = false is not reset; $ ('. close-t '). focus (function () {tapCloseButton = true ;}); setTimeout (function () {if (! TapCloseButton) {$ ('. search-input '). addClass ('search-before'); values ('.close').css ('display', 'None'); document. getElementById ('search '). value = ''; }}, 10 );});

The focus judgment step is delayed, so the focus has been moved from the body to the actually clicked element, and then the focus is determined to see if it is a clearing key.

The above chrome judges whether to click the input label or the implementation method of the remaining labels is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support to 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.