file3,files是什么对象?
程序好像不全!

解决方案 »

  1.   

    file1,2,3是表格单元格,也就是一个表格里动态插入单元格
      

  2.   

    <script>
    function datacheck()
    {
      var b;
      b=(document.all.Text1.value==0)||(document.all.Text1.value="");
      if (b==true)
      {
      alert("Text1为空或0");
      return false;;
      }
      
      b=(document.all.project1.value==0)||(document.all.project1.value="")
      if (b==true)
      {
      alert("project1为空或0");
      return false;
      }
      return true;}
    </script>
    <table>
    <tr>
    <td>
    <input name="hours1" align="lift" type="text" value="0" size="2" maxlength="2" ID=Text1>
    </td>
    </tr>
    <tr><td>
    <input name="project1"  type="text" id="project1">
    </td></tr>
    <tr><td>
    <img src="images/search.gif" name="add1" width="24" height="24" border="0" align="absmiddle" onclick="window.open('projectlist.jsp?nfiles=fe1')">
    </td></tr>
    </table>
    <input type="button" onclick="return datacheck()"  value="提交" ID=Submit1>
      

  3.   

    答clare2003(忘情火):我说的是有好几个文本,ID是 text+变量比如text1,text2,text3,我要一个循环判断这些text里哪个是0或者空,如果有的话就跳出提示。我把你那个加工了一下但是不行,哪位高手帮我耐心点看看哪里错了~~好吗,请耐心点哦,感激不尽?
    说明:file1,file2,file3是表中单元格,动态生成的text是这样子的input type="text" name="hours'+nfiles+'"
    <script>
    var nfiles = 2;
    function Expand(){
    nfiles++;
    if (nfiles>6) {
    alert("参与工程数不能超过5个");
    }else {
    file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时');
    file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">');
    file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">');
    }
    return false;
    }
    function datacheck()
    {
    for(int i=2;i<=nfiles;i++)
     { var b;
      b=(document.all.hours'+i+'.value==0)||(document.all.hours'+i+'.value="")
      if (b==true)
      {
      alert("Text为空或0");
      return false;;
      }
      
      b=(document.all.project'+i+'.value==0)||(document.all.project'+i+'.value="")
      if (b==true)
      {
      alert("project1为空或0");
      return false;
      }
      return true;
    }
    }
    }
    </script>
      

  4.   

    <script>
    var nfiles = 2;
    function Expand(){
    nfiles++;
    if (nfiles>6) {
    alert("参与工程数不能超过5个");
    }else {
    file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时');
    file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">');
    file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">');
    }
    return false;
    }
    function datacheck()
    {
    // EROROR int:
    for(var i=2;i<=nfiles;i++)
    {
      //ERROR
      var $1=document.getElementById("hours"+i).value;
      if ($1=="0"||$1=="")
      {
      alert("Text为空或0");
      return false;
      }
      var $2=document.getElementById("project"+i).value;
      //ERROR
      if ($2==""||$2=="0")
      {
      alert("project1为空或0");
      return false;
      }
      return true;
    }
    }
    </script>
      

  5.   

    我在form 里调用这个JS函数:
    <form name="form1" method="post" onsubmit="return datacheck();"  action="executeroolbook.jsp">
    为什么还是没有判断是否为空或零就递交了呢?递交到executeroolbook.jsp后数据库也更新了,就是没跳出alert~~?