Solution to the problem of text position jumping when the search text box leaves the focus

Solution to the problem of text position jumping when the search text box leaves the focus

When setting the text in the search text box, the position jumps when leaving the focus

Copy code
The code is as follows:

//Search text box
$("#txtSearch").focus(function () {
if ($(this).val() == "Please enter the search keyword") {
$(this).val("");
$(this).css("color", "black");
}
}).blur(function () {
if ($(this).val() == "") {
$(this).css("color", "gray").val("Please enter the search keyword");
}
});

Add in css

Copy code
The code is as follows:

#txtSearch
{
width:480px;
height:20px;
vertical-align:middle;
}

<<:  How to implement horizontal bar chart with percentage in echarts

>>:  Teach you to quickly build a web cluster project based on nginx

Recommend

Native js to implement form validation function

Table of contents When developing, analyzing the ...

How to process local images dynamically loaded in Vue

Find the problem Today I encountered a problem of...

Linux uses binary mode to install mysql

This article shares the specific steps of install...

Instance method for mysql string concatenation and setting null value

#String concatenation concat(s1,s2); concatenate ...

Summary of methods for finding and deleting duplicate data in MySQL tables

Sometimes we save a lot of duplicate data in the ...

js to implement file upload style details

Table of contents 1. Overview 2. Parameters for c...

Detailed explanation of the basic functions and usage of MySQL foreign keys

This article uses examples to illustrate the basi...

MySQL 8.0.11 Installation Tutorial under Windows

This article records the installation tutorial of...

How to find slow SQL statements in MySQL

How to find slow SQL statements in MySQL? This ma...

Mysql get table comment field operation

I won't say much nonsense, let's just loo...

Ubuntu 20.04 firewall settings simple tutorial (novice)

Preface In today's increasingly convenient In...

How to manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

js Promise concurrent control method

Table of contents question background Idea & ...

MySQL initialization password operation under Mac

A simple record of the database startup problems ...