JavaScript基础教程

文章39 |   阅读 17495 |   点赞0

来源:https://blog.csdn.net/u011541946/category_6887610.html

JavaScript学习笔记17-与或非处理复杂的条件

x33g5p2x  于2022-03-06 转载在 其他  
字(0.7k)|赞(0)|评价(0)|浏览(442)

接着前面一篇文章的内容,这里我们来学习下用逻辑与和逻辑或来处理前面的场景。

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
</head>
<body>
<script type ="text/javascript">
		var firstName = "Anthony";
		var lastName = "Liu";
		// 逻辑与
		if ((firstName == "Anthony") && (lastName == "Liu")){
			document.write("Yeah, That is my name." + "<br />");
		}
		// 逻辑或
		if ((firstName == "Anthony") || (lastName == "Wang") ){
			document.write("只要有一个符合就打印");
		}
</script>
</body>
</html>

上面介绍了逻辑与和逻辑或,逻辑非(!!),可以自己去练习下。

相关文章