批改状态:合格
老师批语:
一、直播的时候听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>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号