本帖最后由 mmqqr 于 2010-02-06 21:45:51 编辑

解决方案 »

  1.   

    用getAttribute取自定义属性<script type="text/javascript"> 
          function CheckForm(oForm) 
          {
              //取得表单的值,用通用取值函数 
              var patt = document.getElementById("che").getAttribute("check");              
              var sVal = document.form1.che.value; 
          //    patt = "^\\S+$"; 
              var reg = new RegExp(patt); 
              if (!reg.test(sVal)) 
                { 
                    //验证不通过,弹出提示warning 
                    alert(document.getElementById("che").getAttribute("warning")); 
                    return false; 
                  } 
              return true; 
          } 
    </script> 
    <form onsubmit="return CheckForm(this)" name="form1"> 
        <input type="text" id="che" name="che" check="^\\S+$" warning="id不能为空,且不能含有空格"> 
        <input type="submit" /> 
    </form>
      

  2.   

    document.form1.che.check不是标准使用:
    document.getElementByTagName("input")[0].attribute["check"].value
      

  3.   

    或者
    document.getElementByTagName("input")lastChild.attribute["check"].value
      

  4.   

    正确的写法
    是getElementsByTagName而不是getElementByTagName
    document.getElementsByTagName("input").lastChild.attribute["check"].value
      

  5.   


    <input type="text" id="che" name="che" check="^\S+$" warning="id不能为空,且不能含有空格"> html里的属性值不需要转义
    你自己在这句之前打印一下看看就知道区别了
    ...
    alert(patt); /// <<<<
    var reg = new RegExp(patt); 
    .../^\\S+$/
    /^\S+$/
      

  6.   

    <script type="text/javascript"> 
          function CheckForm(oForm) 
          { 
              if (/\s+/.test(document.getElementById("che").value)||document.getElementById("che").value=="")
                { 
                    alert("输入不能为空或者带空格!");
                    return false; 
                  } 
              return true; 
          } 
    </script> 
    </head>     <form  onsubmit="return CheckForm(this)" name="form1"> 
        <input type="text" id="che" /> 
        <input type=submit /> 
        </form> 
    弄本标准点的书吧 你弄的这些只支持ie
      

  7.   

    <script type="text/javascript"> 
          function CheckForm(oForm) 
          { 
              if (/\s+|^$/.test(document.getElementById("che").value))
                { 
                    alert("输入不能为空或者带空格!");
                    return false; 
                  } 
              return true; 
          } 
    </script> 
    </head>     <form  onsubmit="return CheckForm(this)" name="form1"> 
        <input type="text" id="che" /> 
        <input type=submit /> 
        </form> 
    这样也行的 更简洁   希望