日期:2014-05-16  浏览次数:20861 次

一个ASP的基础问题
紧急帮朋友写个asp的代码,由于从来没用过asp,有个基础问题咨询一下大侠们。
检查输入框为空则停留在本页面,不为空则跳转到下个页面,但是代码不执行,跳转不了(我用的操作系统是win7),请帮忙看看代码有什么问题。代码如下:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试</title>
<script language="VBScript">
Sub cmdNext_onClick
    dim msg
    if len(trim(document.form1.txtSchoolName.value))=0 then
        alert("请输入学校名称!")
        document.form1.txtSchoolName.focus 
    else
        document.form1.submit
    end if    
end sub
</script>
</head>
<body>
<form name="form1" method="post" action="step2.asp">
<input name="txtSchoolName" size="50" height="40" style="float: left"><p>
<input type="button" width="20" value="下一步" name="cmdNext">
<input type="reset" width="20" value="重置" name="cmdClear">
</form>
</body>
</html>

------解决方案--------------------
len(trim(document.form1.txtSchoolName.value))==0
------解决方案--------------------
代码没问题。不过,你的页面只能在IE的低版本中运行,非IE和IE10之后都不支持vbscript
------解决方案--------------------
<script language="javascript">
window.onload=function(){
    document.form1.cmdNext.onclick=function(){
        var v = document.form1.txtSchoolName.value;
        v = v.replace(/(^\s+)
------解决方案--------------------
(\s+$)/,"");
        if(v==""){
             alert("请输入学校名称!")
             document.form1.txtSchoolName.focus();
        }
        else{
             document.form1.submit();
        }
    }
}
 </script>