Home >Web Front-end >JS Tutorial >JavaScript implements a method for the default display of the background image in the text box to disappear after gaining focus
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