javascript代码:
function checkinput() { var googleinput=document.getElementById("googleinput"); if (googleinput.value.length<=0 || googleinput.value=="请输入你想查询的内容") { alert("请输入你想查找的内容"); googleinput.focus(); return false; } else{ setTimeout("clearit()",1000); //1秒之后对文本框中的内容进行清空 return true; } } function clearit(){ var googleinput=document.getElementById("googleinput"); googleinput.value=""; } function inputfocus(){ var googleinput=document.getElementById("googleinput"); googleinput.style.color="#000"; if(googleinput.value=="请输入你想查询的内容"){ googleinput.value=""; } } function inputblur(){ var googleinput=document.getElementById("googleinput"); if(googleinput.value.length<=0){ googleinput.value="请输入你想查询的内容"; googleinput.style.color="#999"; } }
网页内容:
<form name="google" action="http://www.google.com.hk/search" method="get" οnsubmit="return checkinput();"> <input type="hidden" value="zh-CN" name="hl" /> <input type="hidden" value="zh-CN" name="inlang" /> <input type="hidden" value="GB2312" name="ie" /> <input type="hidden" value="GB2312" name="oe" /> <input type="hidden" value="www.anchao.org.cn" name="domains" /> <input type="hidden" value="www.anchao.org.cn" name="sitesearch" /> <input type="text" id="googleinput" name="q" οnfοcus="inputfocus()" οnblur="inputblur()" style="color:#999;" mce_style="color:#999;" value="请输入你想查询的内容" autocomplete="off" class="search" /> <input name="cx" type="submit" value="查询" /> </form>