Blogger Information
Blog 5
fans 0
comment 0
visits 4036
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js数组常用函数及js引用到html中的三种方式2019年1月16日20点
清玉的博客
Original
897 people have browsed it

一、直播的时候听js有点琢磨不透,通过VIP的课程学习后再看一遍直播课理解的更加深刻些,下边是我补的作业,js数组常用函数及js引用到html中的三种方式:

实例

<!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>js数组常用函数及js引用到html中的三种方式</title>
</head>

<body>
    <script>
        var arr = [1,2,3,4,5,6,7,8];
        //增加数组元素
        arr.splice(2,0,'php');
        console.log(arr);
        //删除数组元素
        arr.splice(3,1);
        console.log(arr);
        //修改数组元素
        arr.splice(0,2,'我来了');
        console.log(arr);
        //从数组中返回选定元素,不包括结束索引位置元素
        var a = arr.slice(1,5);
        console.log(a);
    </script>
    <!-- js调用方法 -->
    <!-- 1、直接在元素事件方法上写js代码 -->
    <div style="width:50px;height:50px;background-color:brown;border-radius:50%" onclick="this.style='width:100px;height:100px;background-color:red;border-radius:50%'"></div>
    <!-- 2、js代码写在的script标签里,仅限当前页面使用 -->
    <form action="">
        <input type="text" name="username" placeholder="用户名">
        <button type="button" onclick="check(username)">验证用户</button>
    </form>
    <script>
        function check(username) {
            if (username.value.length === 0) {
                alert('请输入用户名');
            } else {
                alert('验证通过,谢谢!');
            }
        }
    </script>
    <!-- 3、js代码在外部js文件中调用 -->
    <script src="js/js.js"></script>
</body>

</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post