ASP VBscript使用逻辑运算中的 and or
2016-03-28 13:32
387 查看
if session("postTime")<>"" and minute(NOW() - session("postTime")) < 1 then
session("postTime")=NOW()
response.write("postisfast")
response.end
end if
如果 if 前面有 session("postTime") = ""
则报错 500
如果postTime = now() 已经赋过值 则 不会报错
再例如
<%
dim a
a = 1
if a=1 and test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
end function
%>
结果为
<hr>in
若将1改为0
<%
dim a
a = 0
if a=1 and test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
response.Write("<hr>")
end function
%>
结果为
<hr>
说明 尽管 and 前面结果为false ,但and 后面都会执行 response.write("<hr>")
或 or
<%
dim a
a = 1
if a=1 or test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
response.Write("<hr>")
end function
%>
其结果也为
<hr>in
不管 前面是否为true 都会执行or后面的代码
结论 当有时 用到判断 and or 时要注意 条件变量是否为空
不与其他语言 一样 使用 && ||作为与或时 ,&&遇到false则结束,or遇到true则结束
例如
<script language="javascript">
var a,b;
a = 1;
if (a==1 || test1()>0){
alert("in");
}
function test1(){
alert("in test1");
return 1;
}
</script>
不会执行test1()
使用 && 时如果前面 a==1为false 也不会去执行test1()
session("postTime")=NOW()
response.write("postisfast")
response.end
end if
如果 if 前面有 session("postTime") = ""
则报错 500
如果postTime = now() 已经赋过值 则 不会报错
再例如
<%
dim a
a = 1
if a=1 and test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
end function
%>
结果为
<hr>in
若将1改为0
<%
dim a
a = 0
if a=1 and test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
response.Write("<hr>")
end function
%>
结果为
<hr>
说明 尽管 and 前面结果为false ,但and 后面都会执行 response.write("<hr>")
或 or
<%
dim a
a = 1
if a=1 or test1() = 0 then
response.Write("in")
end if
%>
<%
function test1()
test1 = 0
response.Write("<hr>")
end function
%>
其结果也为
<hr>in
不管 前面是否为true 都会执行or后面的代码
结论 当有时 用到判断 and or 时要注意 条件变量是否为空
不与其他语言 一样 使用 && ||作为与或时 ,&&遇到false则结束,or遇到true则结束
例如
<script language="javascript">
var a,b;
a = 1;
if (a==1 || test1()>0){
alert("in");
}
function test1(){
alert("in test1");
return 1;
}
</script>
不会执行test1()
使用 && 时如果前面 a==1为false 也不会去执行test1()
相关文章推荐
- [树莓派2]--系统的安装
- asp.net模拟请求
- Asp.Net读写XML简单方法
- Spring AOP的使用 基于全注解AspectJ
- ASP.NET通过byte正确安全的判断上传文件格式
- asp实现Ajax百度搜索提示的效果
- ASP.NET总结C#中7种获取当前路径的方法
- ASP.NET MVC Form验证
- ASP.NET通过byte正确安全的判断上传文件格式
- ASP.NET 5已终结,迎来ASP.NET Core 1.0和.NET Core 1.0
- ASP.NET实现QQ、微信、新浪微博OAuth2.0授权登录 原创
- 详解ASP.NET MVC Form表单验证
- 树莓派(raspberry)启用root账户
- ASP.NET中多页面传值的理解
- Asp.net MVC的传值方式(一)
- Asp.net中配置Web.config 的UrlRewrite实现伪静态页面的代码
- 基于轻量型Web服务器Raspkate的RESTful API的实现
- DRP之旅(2)——当ASP遇到JSP
- 解决Asp.net页面找不到ajaxpro相关文件问题
- ASP.NET WebForm / MVC 源码分析