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","图书数量必填");
}
{
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","图书数量必填");
}
checkTime函数中,变量 bookTime改成 bookTime1
var bookTime1=document.getElementById("bookTime").value;
if(bookTime1.indexOf("-") <0)
<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>