Home > Web Front-end > JS Tutorial > body text

JavaScript implements a method for the default display of the background image in the text box to disappear after gaining focus

PHPz
Release: 2018-10-12 16:48:47
forward
1254 people have browsed it

This article mainly introduces the JavaScript method to implement the default display background image in the text box to disappear after gaining focus. It involves JavaScript related operation skills for page element styles and attributes. Friends in need can refer to the following:

This is the html code:

<p class="contain">
    <p class="inputFullNameContain"><input class="inputFullName" type="text" id="search_content" /> </p>
    </p>
Copy after login

The following is the js code:

 <script type="text/javascript" >
     (function () {
         var id = document.getElementById('search_content');
         if (id) {
             var name = id;
             var unclicked = function () {
                 if (name.value == '') {
                     name.style.background = 'url("images/inputBackground.png") no-repeat center';
                 }
             };
             var clicked = function () {
                 name.style.background = 'none';
             };
             name.onfocus = clicked;
             name.onblur = unclicked;
             unclicked();
         }
     })();
</script>
Copy after login

For more related tutorials, please visit JavaScript Tutorial

Related labels:
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!