网页输入框默认文字出现与消失

来源:互联网 发布:哪里可以弄到淘宝账号 编辑:程序博客网 时间:2024/06/01 16:31
 

 

首先,编写一下JS:

<script type="text/javascript">//得到焦点时触发事件function OnFocusFun(element,elementvalue){    if(element.value==elementvalue)    {        element.value="";        element.style.color="#000";    }}//离开输入框时触发事件function OnBlurFun(element,elementvalue){    if(element.value==""||element.value.replace(/\s/g,"")=="")    {        element.value=elementvalue;            element.style.color="#999";    }}function check(form){if(form.searchTag.value == ""){alert("关键字不能为空!");form.searchTag.focus();return false;}form.submit.disabled = true;}</script>


在网页中,编写输入框:

<INPUT  type="text" value="想找什么?输入类别或关键字试试" id=search_keywordclass="f_c_gray2 txt_search_gray txt_search" style="color:#999" onfocus="OnFocusFun(this,'想找什么?输入类别或关键字试试')"onblur="OnBlurFun(this,'想找什么?输入类别或关键字试试')" name="searchTag" >

原创粉丝点击