Posted in Javascript onJuly 01, 2015
本文实例讲述了JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法。分享给大家供大家参考。具体如下:
html代码:
<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代码:
<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.background = '#FFFFFF url(images/googbg.png) left no-repeat'; } }; var clicked = function() { name.style.background = '#ffffff'; }; name.onfocus = clicked; name.onblur = unclicked; unclicked(); } })(); </script>
希望本文所述对大家的javascript程序设计有所帮助。
JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法
- Author -
不吃皮蛋声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@