zoukankan      html  css  js  c++  java
  • 条件运算符

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>条件运算符</title>
    	<style type="text/css">
    		*{margin:0; padding: 0;}
    		body{ line-height: 30px; }
    		#demo{ color: red; }
    	</style>
    </head>
    <body>
    <p>点击按钮检查测年龄</p>
    年龄:<input type="text" value="18" id="age" />
    <p>是否达到投票年龄?</p>
    <button onclick="myFunction()">点击按钮</button>
    <p id="demo"></p>
    <script type="text/javascript">
    	function myFunction(){
    		var age,voteable;
    		age=document.getElementById('age').value;
    		voteable=(age<18)?"年龄太小":"年龄已到达";
    		document.getElementById('demo').innerHTML=voteable;
    	}
    </script>
    </body>
    </html>
    

    如果变量 age 中的值小于 18,则向变量 voteable 赋值 "年龄太小",否则赋值 "年龄已达到"。

    实例:

  • 相关阅读:
    厕所惊魂
    感谢协助学生返校,邀请交警合影留念
    小丑杀人
    东芝Toshiba e-STUDIO打印身份证
    JavaScript
    html
    pymysql模块
    线程
    队列与进程池
    网络编程
  • 原文地址:https://www.cnblogs.com/huanghuali/p/6640726.html
Copyright © 2011-2022 走看看