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>
  • 相关阅读:
    取得窗口大小和窗口位置兼容所有浏览器的js代码
    一个简单易用的导出Excel类
    如何快速启动chrome插件
    网页表单设计案例
    Ubuntu下的打包解包
    The source file is different from when the module was built. Would you like the debugger to use it anyway?
    FFisher分布
    kalman filter
    Group delay Matlab simulate
    24位位图格式解析
  • 原文地址:https://www.cnblogs.com/lhl66/p/9548644.html
Copyright © 2011-2022 走看看