This example describes the method by which the default display background picture in the JavaScript implementation text box disappears after the focus has been obtained. Share to everyone for your reference. as follows:
HTML code:
?
1 2 3 4 5 6 7 8 9 |
<form name= "Searchform" id= "Search-form" > <div> <b>Search</b> <input type= "text" Name= " Txtinput "title=" Enter the terms you wish to search for. "/> <input type=" Submit "value=" go! "class=" Submit "style=" cursor:pointer; "/> </div> </form> |
JS Code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<script type= "Text/javascript" language= "JavaScript" > (function () {var id = document.getElementById (' Search-form '); if (ID && id.txtinput) {var name = id.txtinput var unclicked = function () {if (Name.value = = ") {name.style.b ackground = ' #FFFFFF url (images/googbg.png) left No-repeat '; } }; var clicked = function () {name.style.background = ' #ffffff ';}; Name.onfocus = clicked; Name.onblur = unclicked; Unclicked (); } })(); </script> |
I hope this article will help you with your JavaScript programming.