function checkTime()
{
 alert("a");
 var bookTime=document.getElementById("bookTime").value;
 if(bookTime.indexOf("-")<0)
 { 
  alert("格式不正确,应符合yyyy-mm-dd");
  return false;
 }
 return true;
}
//添加书籍验证
function checkaddbook()
{
 return checkText("bookName","书名必填")&&checkText("bookAuthor","作者必填")
 &&checkText("bookPublisher","出版社必填")&&checkText("bookTime","出版日期必填")
 &&checkTime()&&checkText("bookIsbn","ISBN号必填")&&checkText("bookPrice","价格必填")
 &&checkText("bookAmount","图书数量必填");
}

解决方案 »

  1.   

    不好意思,有点急~问题忘注了,我的问题是,checkaddbook() 这个函数调用不了checkTime() 函数,为什么呢?
      

  2.   

    如果input的name是bookTime的话
    checkTime函数中,变量 bookTime改成 bookTime1
    var bookTime1=document.getElementById("bookTime").value; 
    if(bookTime1.indexOf("-") <0) 
      

  3.   

    四楼方法我试过的,不行~还有没有其他的方法啊?input的name是bookTime
      

  4.   

    ie8下测试过的代码:<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title></title> 
    <script type="text/javascript">
    function checkTime() 

      var bookTime1=document.getElementById("bookTime").value; 
      if(bookTime1.indexOf("-") <0) 
      { 
        alert("格式不正确,应符合yyyy-mm-dd"); 
        return false; 
      } 
      return true; 

    function checkText(){
    return true;
    }
    //添加书籍验证 
    function checkaddbook() 

    return checkText("bookName","书名必填")&&checkText("bookAuthor","作者必填") 
    &&checkText("bookPublisher","出版社必填")&&checkText("bookTime","出版日期必填") 
    &&checkTime()&&checkText("bookIsbn","ISBN号必填")&&checkText("bookPrice","价格必填") 
    &&checkText("bookAmount","图书数量必填"); 
    }
    </script> 
    </head> 
    <body> 
    <input id="bookTime" name="bookTime" value="2009-1-1">
    <input type="button" value="xxxx" onclick="alert(checkaddbook())">
    </body>
    </html> 
      

  5.   

    bookTime.indexOf("-") <0 不觉得这段代码有问题吗? 
      

  6.   

    bookTime.indexOf("-") <0 不觉得这段代码有问题吗? 
      

  7.   

    bookTime.indexOf("-") <0 不觉得这段代码有问题吗? 
      

  8.   

    没看出什么问题。或者没有调用到checkTime,是因为在checkText那里已经报错了?
      

  9.   

    没看出来哪错了,如果checktime对的话,应该是checkText有问题,你可以分开一个一个来测试checkText