<html>
<head>
<script type="text/javascript">
function check()
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
}
function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
window.alert(tips);
document.getElementById("soform").action="#";
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br />
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
<head>
<script type="text/javascript">
function check()
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
}
function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
window.alert(tips);
document.getElementById("soform").action="#";
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br />
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
<head>
<script type="text/javascript">
function check()
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
} function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
window.alert(tips);
event.returnValue = false;
event.cancel = true;
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br /> <input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
document.getElementById("soform").setAttribute("action","");
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
window.alert(tips);
isNone = function(){};
event.returnValue = false;
event.cancel = true;
}
}
这样呢
<head>
<script type="text/javascript">
function check()
{
try
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
}
catch(err)
{
event.returnValue = false;
event.cancel = true;
}
} function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
window.alert(tips);
throw("Error Happens!");
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br /> <input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
isNone用13楼的throw("")
function check()
{
try{
……
return true;
}
catch(e)
{
return false
}
}
<head>
<script type="text/javascript">
function check()
{
var flag = 1;
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
} function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "" && flag)
{
window.alert(tips);
event.returnValue = false;
event.cancel = true;
flag = 0;
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br /> <input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
<head>
<script type="text/javascript">
var flag=1;
function check()
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
} function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if(flag==1) {
if (txt.value == "")
{ flag=0;
window.alert(tips);
event.returnValue = false;
event.cancel = true;
}
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br /> <input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function check()
{
try
{
isNone("username","用户名有能为空");
isNone("postcode","邮编不能为空");
isNone("handset","手机不能为空");
return true;
}
catch(err)
{
return false;
}
} function isNone(txtID,tips)
{
var txt = document.getElementById(txtID);
if (txt.value == "")
{
alert(tips)
throw("Error Happens!");
}
}
</script>
</head>
<body>
<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="return check();">
<input type="text" id="username" name="username" />用户名 <br />
<input type="text" id="postcode" name="postcode" />邮编 <br />
<input type="text" id="handset" name="handset" />手机 <br /> <input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
</body>
</html>
程序员在深圳QQ群,交流产生思想碰撞. 部份专业群:
程序员在深圳c++群15195967
程序员在深圳英语学习群:23864353
程序员在深圳c++Ⅱ17409451
程序员在深圳嵌入式开发群37489763
程序员在深圳移动开发群31501597
程序员在深圳创业群33653422 部份高级程序员群:
高级群I:17538442
高级群II:7120862 部份初、中级程序员群:
第三群:2650485
第五群:29537639
第四群:28702746
第六群:10590618
第七群:10543585
第八群:12006492
第九群:19063074
第十群:2883885
第十一群:25460595
第十二群:9663807 深圳程序员QQ群联盟成立三年多,拥有三十个以上的QQ群,人数超二千多人,大量经验丰富的老手,成员从业于大公司(如微软、IBM,SUN,华为 )、来自国内著名高校和研究院成员,和有丰富实践经验的高级程序员、系统分析员(包括参加过上亿元的项目的架构师),有很热爱技术的成员 (包括自己写操作系统),还有少数女程序员。推荐:深程高级群I:17538442 深程高级群II:7120862 (深程高级群不欢迎新手,如果在深圳,月薪 6K以下的别加入) c++:15195967 mobile:31501597嵌入式:37489763
——————————————————————————————————————————
如果你不是第一次看到此广告,说明我们最近T了一些人,因为我们要不断提升群的质量,保证名副其实.
-------------------------------------------------------------------------------------
在通过电邮、新闻组或者聊天室提出技术问题前,检查你有没有做到:
1. 通读手册,试着自己找答案。
2. 在FAQ里找答案(一份维护得好的FAQ可以包罗万象:)。
3. 在网上搜索(个人推荐google~)。
4. 向你身边精于此道的朋友打听。
我想我们首先应该*自己解决问题,然后才是问! *****************************************************************************
想在isNone中try(因为它只有一个)
真心感谢大家的帮助!
根据22楼思维(22楼不如23楼,但23是吸取了22的思想),问题已经解决!tengfei3003 2楼,5楼,9楼,12楼,
YH_Random 4楼,6楼
yonghengdexingxing 8楼,13楼_,28楼,
neo_yoho 15楼,24楼,30楼,
hehe2006jian 20楼(不知其意)
xf_pan 22楼(有错误,但是思路正确),
chinmo 23楼(由22楼而来),25楼,26楼,27楼,
sz000000001 29楼(广告)
问题已经解决,等我处理手头事情立即结帖
//其它函数
String.prototype.trim = function ()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}function $(objID) //根据ID返回对象
{
return document.getElementById(objID);
}
function checkForm()
{
this.flag = true;
this.txtObj;
this.tipStr;
this.getTextObject = function (txtID,tips) //参数说明:txtID 文本框ID,tips 错误提示信息
{
this.txtObj = $(txtID);
this.tipStr = tips;
}
this.errorTip = function () //错误提示
{
window.alert(this.tipStr);
this.txtObj.focus(); event.returnValue = false;
event.cancel = true;
}
this.isNone = function (txtID,tips) //空值检测
{
this.getTextObject(txtID,tips); if (this.txtObj.value.trim().length == 0 && this.flag)
{
this.flag = false;
this.errorTip();
}
}
}<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="cf();">
<input type="text" id="username" name="username" />用户名<br />
<input type="text" id="postcode" name="postcode" />邮编<br />
<input type="text" id="handset" name="handset" />手机<br />
<input type="text" id="idcard" name="idcard" />身份证<br />
<input type="text" id="qq" name="qq" />QQ<br />
<input type="text" id="email" name="email" />email<br /><input type="submit" value="提交" />
<input type="reset" value="重置" />
</form><script language="javascript" type="text/javascript">
var c = new checkForm();function cf()
{
c.flag = true;
c.isNone("username","用户名不能为空");
c.isNone("postcode","邮编不能为空");
c.isNone("handset","手机不能为空");
}
</script>
目前还不能兼容Firefox,希望高手指教!
String.prototype.trim = function ()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}function $(objID) //根据ID返回对象
{
return document.getElementById(objID);
}function isIE() //检测浏览器类型
{
if (window.ActiveXObject)
return true;
else
return false;
}function checkForm()
{
this.eventObj;
this.flag = true;
this.txtObj;
this.tipStr;
this.getTextObject = function (txtID,tips) //参数说明:txtID 文本框ID,tips 错误提示信息
{
this.txtObj = $(txtID);
this.tipStr = tips;
}
this.errorTip = function () //错误提示
{
window.alert(this.tipStr);
this.txtObj.focus(); if (isIE())
this.eventObj.returnValue = false;
else
this.eventObj.preventDefault();
}
this.isNone = function (txtID,tips) //空值检测
{
this.getTextObject(txtID,tips); if (this.txtObj.value.trim().length == 0 && this.flag)
{
this.flag = false;
this.errorTip();
}
}
}<form id="soform" name="soform" method="post" action="Count.asp" onsubmit="cf(event);">
<input type="text" id="username" name="username" />用户名<br />
<input type="text" id="postcode" name="postcode" />邮编<br />
<input type="text" id="handset" name="handset" />手机<br />
<input type="text" id="idcard" name="idcard" />身份证<br />
<input type="text" id="qq" name="qq" />QQ<br />
<input type="text" id="email" name="email" />email<br /><input type="submit" value="提交" />
<input type="reset" value="重置" />
</form><script language="javascript" type="text/javascript">
var c = new checkForm();function cf(eventObject)
{
c.eventObj = eventObject;
c.flag = true; c.isNone("username","用户名不能为空");
c.isNone("postcode","邮编不能为空");
c.isNone("handset","手机不能为空");
}
</script>