Home > Web Front-end > JS Tutorial > Based on jquery implementation, when moving into the empty text box on the page, let it become the focus, and move out to clear the focus_jquery

Based on jquery implementation, when moving into the empty text box on the page, let it become the focus, and move out to clear the focus_jquery

WBOY
Release: 2016-05-16 18:04:31
Original
914 people have browsed it
Copy code The code is as follows:

var Page_INIT = function () {
$(document). bind("mouseover", function (e) {//mouse moves into
if (e.target.tagName.toUpperCase() == "INPUT") {
var input = e.target;
if (input.type == "text") {//If it is a text box
if (window.Page_FocusTimer) {//If it is in the focus state
window.clearTimeout(window.Page_FocusTimer);//Clear the focus state
}
window.Page_FocusTimer = window.setTimeout(function () { //Execute this anonymous method every 0.2 milliseconds
if (!input.value) {//If the content is empty , then set as focus
try {
input.focus();
} catch (e) { }
}
}, 200);
}
}
}).bind("mouseout", function (e) {//Mouse out
if (e.target.tagName.toUpperCase() == "INPUT") { //The event source object being processed If the name (i.e. HTML tag) is converted to uppercase, it will be INPUT
var input = e.target;
if (input.type == "text") {
if (window.Page_FocusTimer) {
window.clearTimeout(window.Page_FocusTimer);
}
}
}
});
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template