zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVASCRIPT开发学习:条件语句

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <p>如果时间早于 20:00,会获得问候 "Good day"。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction(){
        var x="";
        var time=new Date().getHours();
        if (time<20){
            x="Good day";
        }
        document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <p>点击这个按钮,获得基于时间的问候。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    <script>
    function myFunction(){
        var x="";
        var time=new Date().getHours();
        if (time<20){
             x="Good day";
         }
        else{
             x="Good evening";
         }
        document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>

    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script type="text/javascript">
    var d = new Date();
    var time = d.getHours();
    if (time<10)
    {
        document.write("<b>早上好</b>");
    }
    else if (time>=10 && time<16)
    {
        document.write("<b>今天好</b>");
    }
    else
    {
        document.write("<b>晚上好!</b>");
    }
    </script>
    <p>
    这个例子演示了 if..else if...else 语句。
    </p>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head> 
    <meta charset="utf-8"> 
    <title>菜鸟教程(runoob.com)</title> 
    </head>
    <body>
    
    <p id="demo"></p>
    <script>
    var r=Math.random();
    var x=document.getElementById("demo")
    if (r>0.5){
        x.innerHTML="<a href='http://www.runoob.com'>访问菜鸟教程</a>";
    }
    else{
        x.innerHTML="<a href='http://wwf.org'>Visit WWF</a>";
    }
    </script>
    
    </body>
    </html>

  • 相关阅读:
    LeetCode:Remove Nth Node From End of List
    链表排序(冒泡、选择、插入、快排、归并、希尔、堆排序)
    快速排序partition过程常见的两种写法+快速排序非递归实现
    LeetCode:Permutations, Permutations II(求全排列)
    LeetCode:3Sum, 3Sum Closest, 4Sum
    LeetCode:Two Sum
    判断一个图是否有环
    c++设计一个无法被继承的类
    设计模式--单例模式
    windows多线程同步互斥--总结
  • 原文地址:https://www.cnblogs.com/tszr/p/10942330.html
Copyright © 2011-2022 走看看