当前位置:编程学习 > JS >>

哪位高手帮帮我,看一下我的javascript为什么不起作用?貌似不提交结果?很着急,谢谢!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>更新用户记录</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="CSS/styles.css"> <script type="text/javascript"> <!-- 检验是否为电话号码--> function chkNum(str) { return str.match(/\d{12}/)!=null; } function chk() { var uid=document.getElementsByName("user_id")[0]; var uname=document.getElementsByName("user_name")[0]; var uage=document.getElementsByName("user_age")[0]; var uphone=document.getElementsByName("user_phone")[0]; if(uid.value==""||uname.value==""||uage.value==""||uphone.value==""){ alert("*标注的不能为空!"); return false; }else if(chkNum(uphone)==false){ alert("电话号码非法!应包含区号,12位,不含非数字字符!"); return false; }else if(uage.value>100||uage.value<0){ alert("年龄非法!应为1~100之间!"); return false; }else{ return true; } } function doUpdate() { if(chk==true){ return window.confirm("是否更新记录?"); }else{ return false; } } function doDel() { return window.confirm("是否删除该记录?"); } </script> </head> <body> <h4>用户管理>></h4> <hr/> <form action="userManage?do=update" method="post" id="add_data_form" onSubmit="return doUpdate()" > 触发方式是这样的
答案:试试直接调用更新的方法,不再判断
if(uid.value==""||uname.value==""||uage.value==""||uphone.value==""){
		alert("*标注的不能为空!");
		return false;
	}else if(chkNum(uphone)==false){
		alert("电话号码非法!应包含区号,12位,不含非数字字符!");
		return false;
	}else if(uage.value>100||uage.value<0){
		alert("年龄非法!应为1~100之间!");
		return false;
	}else{
		 doUpdate();
	}
}
而更新的方法改为
function doUpdate()
{	
 return window.confirm("是否更新记录?");
}
其他:function doUpdate()
{	
	if(chk==true){//chk()是方法,不能当属性用   if(chk()){....}else{.... }
		return window.confirm("是否更新记录?");
	}else{
		return false;
	}  
} function doUpdate()
{	
	if(chk==true){
		return window.confirm("是否更新记录?");
	}else{
		return false;
	}  
}
这里的chk不对,应该是 chk() 
chk是函数,使用的时候不可漏掉括号 

上一个:如何将很多用javascript翻页的网页表格数据导入excel?
下一个:JavaScript的文字跟随鼠标

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,