zoukankan      html  css  js  c++  java
  • 原生js的容易忽略的相似点(一)

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title>原生js测试</title>
            <script type="text/javascript">
                //onload 和 onunload 事件会在用户进入或离开页面时被触发
                window.onload = function(){
                    alert('进入页面花了多少时间'+new Date().getTime())
                }
            </script>
        </head>
    
        <body>
            <span id='test'></span>
            <script type="text/javascript">
                //1、带参数retur 
                function aa(argument1, argument2) {
                    console.log(argument1, argument2) //1 2
                    return argument1 + argument2
                }
                console.log(aa(1, 2)) //3
                //2、不带参数retur 内部变量;
                //在使用 return 语句时,函数会停止执行,并返回指定的值。
                function bb() {
                    var x = 5;
                    return x;
                }
                console.log(bb()) //5
                //3、直接调用函数 
                var ele = document.getElementById('test').innerHTML = bb(); //页面显示5
                console.log(ele, 'ele') //5 ele
                //4、变量的赋值理解
                x = 10;
                y = 5;
                x = y;
                console.log(x, 'xxxx'); //5 "xxxx"
                //5、三元运算符的运用
                var age = 8;
                var val = (age > 10) ? 'ok' : 'no'
                console.log(val, 'val') //no val
                //6.case语句块
                var toDay;
                var day = new Date().getDay();
                switch(day) {
                    case 0:
                        toDay = "Today it's Sunday";
                        break;
                    case 1:
                        toDay = "Today it's Monday";
                        break;
                    case 2:
                        toDay = "Today it's Tuesday";
                        break;
                    case 3:
                        toDay = "Today it's Wednesday";
                        break;
                    case 4:
                        toDay = "Today it's Thursday";
                        break;
                    case 5:
                        toDay = "Today it's Friday";
                        break;
                    case 6:
                        toDay = "Today it's Saturday";
                        break;
                }
                console.log(toDay,'toDay')//Today it's Tuesday toDay
                //7、dom操作;
                // document.getElementById(id).innerHTML=new HTML          改变 HTML内容
                // document.getElementById(id).style.property=new style    更改样式
                // document.getElementById(id).attribute=new value         改变 HTML属性
            </script>
        </body>
    
    </html>
  • 相关阅读:
    7-5 幸运彩票 (15分)
    基于Python实现学生管理系统
    NB-IoT模块烧写详细过程
    IAR软件使用的快捷键配置以及配置cc2530环境
    7-54 求方程的解 (10 分)
    7-52 计算球体积 (10 分)
    7-51 号码牌的制作 (10 分)
    7-48 输出星期名缩写 (70 分)
    7-49 求前n项的阶乘之和 (15 分)
    7-46 jmu-python-求单词长度 (10 分)
  • 原文地址:https://www.cnblogs.com/lhl66/p/9548644.html
Copyright © 2011-2022 走看看