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 赋值 "年龄太小",否则赋值 "年龄已达到"。

    实例:

  • 相关阅读:
    python向mysql中插入数字、字符串、日期总结
    selenium鼠标事件
    iOS hook
    网络抓包篇
    frida IOS环境搭建
    git
    $emit
    better-scroll无法滚动的问题。
    this.$nextTick()作用
    better-scroll
  • 原文地址:https://www.cnblogs.com/huanghuali/p/6640726.html
Copyright © 2011-2022 走看看