本文主要是介绍JavaScript学习笔记15-if-else语句,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前面介绍了if语句的,接下来学习else,和其他语言一样,if和else一般一块使用。就像生活中我们做决定,如果什么,那么做什么,否则,做什么。就这么简单,来看看示例。
<! 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 apples = 35;var hotdogs = 76;if (apples < hotdogs){document.write("I like hotdogs!");}else{document.write(" I like apples");}
</script>
</body>
</html>
这篇关于JavaScript学习笔记15-if-else语句的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!