Home  >  Article  >  Web Front-end  >  JavaScript implements a method for the default display of the background image in the text box to disappear after gaining focus

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

PHPz
PHPzforward
2016-05-16 15:51:581264browse

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>

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>

For more related tutorials, please visit JavaScript Tutorial

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete