首先,编写一下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_keyword
class="f_c_gray2 txt_search_gray txt_search" style="color:#999"
οnfοcus="OnFocusFun(this,'想找什么?输入类别或关键字试试')"
οnblur="OnBlurFun(this,'想找什么?输入类别或关键字试试')" name="searchTag" >