博客列表 >JavaScript基础作业练习_1022

JavaScript基础作业练习_1022

Jet的博客
Jet的博客原创
2019年10月23日 11:15:17594浏览
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        /*
                                                                                                                                function func() {
                                                                                                                                    var a = 123;
                                                                                                                                    alert(a);
                                                                                                                                    return 'abc';
                                                                                                                                }
                                                                                                                                alert(func());
                                                                                                                                */
        /*
                var score = 90;
                if (score < 60) {
                    alert('不及格');
                }
                if (score >= 60 && score < 80) {
                    alert('良好');
                }
                if (score >= 80 && score < 90) {
                    alert('不错哦');
                }
                if (score >= 90 && score < 100) {
                    alert('优秀');
                }
        */
        /*
                var num = 6;
                for (i = 0; i < num; i++) {
                    alert('i=' + i);
                }

                var num = 1;
                while (num < 6) {
                    alert('num=' + num);
                    num++;
                }

                var num = 6;
                while (num > 6) {
                    alert('num=' + num);
                }
        */
        /*
        var num = 'asd';
        num = parseInt(num);
        //parseInt 转换为整型
        alert(typeof(num));
        if (isNaN(num)) {
            alert('转换失败');
        }
        if (isNumber(num)) {
            alert(num);
        }
        */
        /*
        var arr = [1, 2, 3, 5, 6];
        //不建议插入数据
        //arr[9] = 44;
        //往数组后面插入数据
        arr.push(44);
        alert('长度是' + arr.length);
        //弹出尾部元素
        var res = arr.pop();
        alert(res);
        console.log(arr);
        alert('长度是' + arr.length);
        */

        //var arr = [1, 2, 3, 5, 6];
        //在第一个位置添加一个元素
        //arr.unshift('abc');
        //删除第一个元素
        //var res = arr.shift();
        //alert(res);
        //console.log(arr);

        var arr = [1, 2, 3, 4, 5, 6];
        //从第几个元素开始删除几个元素
        //var res = arr.splice(2, 4);
        //console.log(res);
        //搜索目标元素,第几个元素开始找;返回改数据索引
        //var res = arr.indexOf(5, 0);
        //alert(res);
        //console.log(arr);

        //数组遍历
        // for (i = 0; i < arr.length; i++) {
        //     console.log(arr[i]);
        // }

        // var i = 0;
        // while (i < arr.length) {
        //     console.log(arr[i]);
        //     i++;
        // }
        function over() {
            console.log('鼠标滑过了');
        }

        function out() {
            console.log('鼠标划走了');
        }
    </script>
</head>

<body>
    <div style="background-color: aqua; width: 200px; height: 80px;" onmouseover="over()" onmouseout="out()"></div>
</body>

</html>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议