急~~无法调用JS事件。。

mysite365 2008-04-14 09:28:07
<input name="submit01" type="submit" onclick="check_reg()" value="提交表单" width="91" height="27" border="0">
<script language="javascript">
function check_reg()
{
if(document.form1.username.value=="") {
alert("对不起,请填写用户名!");
document.form1.username.focus();
return;
}
if(document.form1.userpassword.value=="" || document.form1.userpassword.value.length < 6 || document.form1.userpassword.value.length >20) {
alert("密码长度不能为空,在6位到20位之间,请重新输入!");
document.form1.userpassword.focus();
return;
}
if(document.form1.userpassword.value != document.form1.userpassword1.value) {
document.form1.userpassword.focus();
document.form1.userpassword.value = '';
document.form1.userpassword1.value = '';
alert("两次输入的密码不同,请重新输入!");
return;
}

if(document.form1.email.value.length!=0)
{
if (document.form1.email.value.charAt(0)=="." ||
document.form1.email.value.charAt(0)=="@"||
document.form1.email.value.indexOf('@', 0) == -1 ||
document.form1.email.value.indexOf('.', 0) == -1 ||
document.form1.email.value.lastIndexOf("@")==document.form1.email.value.length-1 ||
document.form1.email.value.lastIndexOf(".")==document.form1.email.value.length-1)
{
alert("Email地址格式不正确!");
document.form1.email.focus();
return;
}

else
{
alert("Email不能为空!");
document.form1.email.focus();
return;
}
}
if(document.form1.quesion.value=="") {
alert("对不起,请填写密码提问!");
document.form1.quesion.focus();
return;
}
if(document.form1.agree.value=="1") {
alert("对不起,你不同意协议内容!");
document.form1.agree.focus();
return;
}
if(document.form1.answer.value=="") {
document.form1.answer.focus();
alert("对不起,请填写密码提问的答案!");
return;
}
if(document.form1.turename.value=="") {
alert("对不起,请填写真实姓名!");
document.form1.turename.focus();
return;
}
if(document.form1.address.value=="") {
alert("对不起,请填写通讯地址!");
document.form1.address.focus();
return;
}

}
if(document.form1.zip.value=="") {
alert("对不起,请填写邮编!");
document.form1.zip.focus();
return;
}
if(document.form1.zip.value.length!=6)
{
document.form1.zip.focus();
alert("对不起,请正确填写邮编!");
return;
}
if(document.form1.phone.value=="")
{
alert("对不起,请留下您的联系电话!");
document.form1.phone.focus();
return;
}
document.form1.submit();
}
</script>  

提示网页中有两个声明的JS,文件。
当我点提交按钮,只是闪一下,什么也不提示。。。。。。。。
谁帮忙解决下。
...全文
132 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
mysite365 2008-04-14
  • 打赏
  • 举报
回复
难道没人知道。。。。。。。。。
mysite365 2008-04-14
  • 打赏
  • 举报
回复

4楼的,可用说下,我的为什么不能调用的原因吗??
照你的改了,还是不能调用的??
还有你的2:onclick="return check_reg()" 提示错误时候返回return false; ,是声明意思???
xiaojing7 2008-04-14
  • 打赏
  • 举报
回复
1:js放<head></head>中间
2:onclick="return check_reg()" 提示错误时候返回return false;
3:不建议使用document.form1.username.value的形式来获取对象的值,
可以参考document.getElementById("username").value 的形式来获取,使用DOM对象!
4:你的方法没一点可读性,这么多js方法,你没发现都是验证为空,为何不写一个方法,直接传进去参数呢?
这样节省你n倍的代码量
mysite365 2008-04-14
  • 打赏
  • 举报
回复
照2楼,3楼修改以后,现象一样。。。。。。。。
deleteall8 2008-04-14
  • 打赏
  • 举报
回复
<script language="javascript">
function check_reg()
{
if(document.form1.username.value=="") {
alert("对不起,请填写用户名!");
document.form1.username.focus();
return;
}
...
</script>
放到前面去

<input name="submit01" type="button" onclick="check_reg()" value="提交表单" width="91" height="27" border="0"> 

文盲老顾 2008-04-14
  • 打赏
  • 举报
回复
使用 FF 的 firebug 查看错误提示

另外,推荐在 form 中使用 onsubmit ,而不推荐在 submit 按钮上使用 onclick
xiaojing7 2008-04-14
  • 打赏
  • 举报
回复
都可以
不过第一个勉强好点
mysite365 2008-04-14
  • 打赏
  • 举报
回复
<td width="52%"><font color="#CC0000">* </font>所属范围:
<select name="scope">
<option value=" " selected>==请选择所属范围==</option>
<option value="0">社会人士</option>
<option value="1">海洋大学</option>
<option value="2">青岛理工大学</option>
<slect>
if(document.form1.scope.value=="")
{
document.form1.scope.focus();
alert("对不起,请选择所属范围!");
return false;
}
或者
if(!document.form1.scope.value)
{
alert("对不起,请选择所属范围!");
return false;
}
上面2个有正确的吗??

我想用JS得到列表或单选按钮是否选择的值,要什么写。。。
scscms太阳光 2008-04-14
  • 打赏
  • 举报
回复
同时
if(document.form1.username.value=="") {
alert("对不起,请填写用户名!");
document.form1.username.focus();
return;
---------------
所有return; 应该改为return false;
scscms太阳光 2008-04-14
  • 打赏
  • 举报
回复
注意:用用这方法吧

<form ACTION="?action=save" METHOD="POST" name="Form1" id="Form1" onSubmit="return check_reg()">
......
<input name="submit01" type="submit" value="提交表单" width="91" height="27" border="0">
</form>
至于JS文件在上在下都没关系的.
xiaojing7 2008-04-14
  • 打赏
  • 举报
回复
给你个例子吧,
www.jingliangliang.cn/others/CommonCheck.js

调用的时候,直接
var Check=function()
{
if(IsEmpty($("Txttest"),"不能为空!"))return false;
if(IsHaveScript($("Txttest"),"脚本"))return false;
//if(IsNotMobileTelephone($("Txttest"),"移动电话"))return false;
//if(ValueCompare($("Txttest"),$("Txttwo").value,"第一个必须第2个的值"))return false;
if(UrlCheck($("Txttest"),"URL"))return false;
}
<input type="button" ID="Btntest" value="测试" onclick="return Check()" />
--------------------
do you know?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧