乐趣区

关于javascript:JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法

本文实例讲述了 JavaScript 实现文本框中默认显示背景图片在取得焦点后隐没的办法。分享给大家供大家参考。具体如下:

html 代码:

?
1 2 3 4 5 6 7 8 9 <form name=”searchform” id=”search-form”> <div> Search <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 代码:

?
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.background = ‘#FFFFFF url(images/googbg.png) left no-repeat’; } }; var clicked = function() { name.style.background = ‘#ffffff’;}; name.onfocus = clicked; name.onb 网站监控 lur = unclicked; unclicked();} })(); </script>
心愿本文所述对大家的 javascript 程序设计有所帮忙。

退出移动版