<input type=text name=text1>
<input type=button value=提交 onclick=woyingjie()>
<script>
function woyingjie(){
if(document.all.text1.value==""){
alert("不能为空");
return false;
}
if(document.all.text1.value.length>10){
alert("不能超过10");
return false;
}
if(document.all.text1.value.indexOf("买")>=0){
alert("不能有'买'字");
return false;
}
}
</script>

解决方案 »

  1.   

    <input onblur=a(this)>
    <script>
    function a(o)
    {
    if(o.value.length>10)
    {
    alert("err")
    o.focus()
    }
    if(o.value.indexOf("求")>-1 || o.value.indexOf("买")>-1)
    {
    alert("求买")
    o.focus()
    }
    }
    </script>
      

  2.   

    <script language=javascript>
    var txt1;
    </script><form name=form1 onsubmit="check();">
    <input type=text name=t1 maxlength=10 onpropertychange="if (this.value.indexOf('求')!=-1 || this.value.indexOf('买')!=-1) this.value=txt1;else txt1=this.value;">
    </form>
      

  3.   

    修正:
    <script language=javascript>
    var txt1='';
    </script><form name=form1 onsubmit="check();">
    <input type=text name=t1 maxlength=10 onpropertychange="if (this.value.indexOf('求')!=-1 || this.value.indexOf('买')!=-1) this.value=txt1;else txt1=this.value;">
    </form>
      

  4.   

    <script language="javascript">
    <!--
      function funcheck()
      {
        var strNote = document.all.T1.value;
        var i;
        if (strNote.length > 10) {alert("出界!"); return false;}
        else
        {
          if (strNote.indexOf('求') != -1) {alert("不能含有'求'字"); return false;}
          if (strNote.indexOf('买') != -1) {alert("不能含有'买'字"); return false;}
        }
      }
    //-->
    </script><input name=T1 size=20>
    <input type=button value=check onclick="funcheck();">