现代码如:
<form id="form_搜索" method="get" action="/search.shtml" target="_blank">
<input type="text"  value="输入关键字" id="_keyword" name="word" onblur="if(this.value=='') {this.value='输入关键字';this.form._keyword.style.color='#D8D8D8'}" onclick="if(this.value=='输入关键字'){this.value='';this.form._keyword.style.color='#000'};stopSearchTextTimer();return false;" onfocus="stopSearchTextTimer();"/>
<button type="button" onclick="document.getElementById('form_搜索').submit();return false;" value="" /></button>
</form>
就是实现当没有输入关键字或者关键字为默认显示的"输入关键字"时,使button按钮无效,以减少无效搜索.直接在以上代码中加吧。

解决方案 »

  1.   

    <form id="form" method="get" action="/search.shtml">
    <input type="text" value="输入关键字" id="keyword"  name="keyword" onblur="if(this.value=='') {this.value='输入关键字';this.form.keyword.style.color='#D8D8D8';document.getElementById('x').disabled='disabled'}" onclick="if(this.value=='输入关键字'){this.value='';this.form.keyword.style.color='#000';document.getElementById('x').disabled=''};return false;"/>
    <button type="button" id="x" onclick="document.getElementById('form').submit();return false;" value="" /></button>
    </form>