| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1094 人关注过本帖
标题:为什么我验证是否为空的语句不好使呢
只看楼主 加入收藏
猫色色
Rank: 2
等 级:论坛游民
帖 子:135
专家分:25
注 册:2006-6-8
结帖率:96%
收藏
 问题点数:0 回复次数:13 
为什么我验证是否为空的语句不好使呢

我用如下代码验证用户名是否为空,可是不知道那错了,就是不起做用,用户名为空照样也能提交过去!请问怎样解决
<head>
<script language="javascript">
function checkForm(){
if(document.frmRegister.tname.value==""){
alert('用户名不能为空');
<%response.write "123"%>
return false;
}
}
</script>
</head>
<body>
<div style="position: absolute; width: 301px; height: 346px; z-index: 1; left: 411px; top: 125px" id="layer1">
<form name="form1" method=get action=zc.asp onsubmit="return checkForm();">
<table border="1" width="303" id="table1" height="395">
<tr>
<td width="56" align="center"><font size="2">用户名</font></td>
<td width="151" colspan="2"><input type="text" name="tname" size="20" id="tname"></td>
<td width="74"> </td>
</tr>
<tr>
<td width="56"> </td>
<td width="40"><input type="submit" value="提交" name="submit"></td>
<td width="105"><input type="reset" value="重置" name="submit1"></td>
<td width="74"> </td>
</tr>
</table>
</form>
</div>

</body>

搜索更多相关主题的帖子: 语句 用户名 验证 script 
2007-01-19 17:21
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
收藏
得分:0 
<script language="javascript">
function checkForm(){
if(document.frmRegister.tname.value==""){
alert('用户名不能为空');
<%response.write "123"%> 改成 <% response.Redirect("#.asp") %>‘在转到当前页面可以么?
return false;
}
}

http://www./
2007-01-19 17:28
猫色色
Rank: 2
等 级:论坛游民
帖 子:135
专家分:25
注 册:2006-6-8
收藏
得分:0 
<%response.write "123"%>
这句话去掉了也不好使

我们在成长
2007-01-19 17:48
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
收藏
得分:0 
<%response.write "123"%>

这句根本不起任何作用的. 你换成<% response.Redirect("#.asp") %>试试
当 document.frmRegister.tname.value=="" 的时候 重新打开 #.asp 这个页面

http://www./
2007-01-19 17:51
猫色色
Rank: 2
等 级:论坛游民
帖 子:135
专家分:25
注 册:2006-6-8
收藏
得分:0 
还是不行呀!
我书上写的
<script language="javascript">
function checkForm(){
if(document.frmRegister.tname.value==""){
alert('用户名不能为空');
return false;
}
}
但是这样也不好使呀!

我们在成长
2007-01-19 17:59
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
收藏
得分:0 
<script language="javascript">
function checkForm(){
if(document.frmRegister.tname.value==""){
alert('用户名不能为空');
<%response.write "123"%>
return false;
}

你先试下 checkForm() 的功能 能不能实现.
form name="form1" method=get action=zc.asp onsubmit="return checkForm();">

你先把 action=zc.asp 去掉.先别传值. 当你用户名 为空的时候 会不会出现123

呵呵 我对 javascript 也不是很懂.

http://www./
2007-01-19 18:09
猫色色
Rank: 2
等 级:论坛游民
帖 子:135
专家分:25
注 册:2006-6-8
收藏
得分:0 
不行!
感觉是onsubmit="return checkForm();">他不好使

我们在成长
2007-01-19 18:21
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
收藏
得分:0 
<html>
<head>
<script language="javascript">
function checkForm(){
if(document.all.tname.value.length>0){
alert("12313213")
}else{
alert("123");
}

}
</script>
</head>
<body>
<div style="position: absolute; width: 301px; height: 346px; z-index: 1; left: 411px; top: 125px" id="layer1">
<form name="form1" method=post action="" onsubmit="return checkForm();">
<table border="1" width="303" id="table1" height="395">
<tr>
<td width="56" align="center"><font size="2">用户名</font></td>
<td width="151" colspan="2"><input type="text" name="tname" size="20" id="tname"></td>
<td width="74"> </td>
</tr>
<tr>
<td width="56"> </td>
<td width="40"><input type="submit" value="提交" name="submit"></td>
<td width="105"><input type="reset" value="重置" name="submit1"></td>
<td width="74"> </td>
</tr>
</table>
</form>
</div>

</body>

http://www./
2007-01-19 18:25
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
收藏
得分:0 
<script language="javascript">
function checkForm(){
if(document.all.tname.value.length>0){
alert("12313213")
}else{
alert("123");
}

}
为空的时候 输出123.不为空的时候输出 12313213.
你试试把你的判断改下..
我上面发的那个可以实现判断的

http://www./
2007-01-19 18:27
猫色色
Rank: 2
等 级:论坛游民
帖 子:135
专家分:25
注 册:2006-6-8
收藏
得分:0 
我按你的试了,输出的结果和你弄的是一样的1
可是我就想不明白为什么弄我的那个却不好使呢1!
兄弟你QQ号是多少

我们在成长
2007-01-19 18:46
快速回复:为什么我验证是否为空的语句不好使呢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024914 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved