Home >Web Front-end >JS Tutorial >jquery's positioning of page focus (the text box changes style when it gets focus)_jquery

jquery's positioning of page focus (the text box changes style when it gets focus)_jquery

WBOY
WBOYOriginal
2016-05-16 18:20:061283browse

Functional implementation:
When users enter text, it would be more user-friendly if the text box they are typing in can be highlighted. We will use jQuery to implement this below.

Implementation principle:
After the document is loaded (ready), add the focus and blur events of the input, and add and delete styles.
Code example:

Copy code The code is as follows:







< ;body>









According to the requirements of the test, after the alert, the cursor should be positioned at the specified position. After checking it, I found that the focus attribute can be easily achieved.

alert("Name cannot be empty!");

//Locate the required focus by id

$("#name").focus();

That is, after the prompt is output, the focus returns to the input item. Similarly, corresponding styles can also be added. It would be more user-friendly if the text box being entered could be highlighted. We will use jQuery to achieve this.

After the document is loaded (ready), add the focus and blur events of the input, and add and delete styles.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn