本课标题:DOM对非表单元素与表单元素的属性操作
引入话术:我们学习事件的目的就是为了方便对DOM进行操作,也就是通过事件去对DOM元素中的属性就行操作,比如单击一个按钮隐藏盒子、光标移入到盒子上盒子变色等。那我们如何结合事件去对元素进行操作呢?那我们先学对非表单元素的属性操作
课堂内容:1)对图片的src属性操作
2)对图片的width/height属性操作
3)对图片的title/alt属性的操作
4)图片的显示与隐藏
案例演示:演示DOM对非表单元素的属性操作(历时25分钟)
引入话术:刚才只是对表单元素属性执行了操作,我们接下来对表单元素进行操作。
课堂内容:1)复习回顾表单及表单元素的组成、特征
2)value属性的操作
3)disabled/checked/selected属性的操作(重点)
4)复习回顾按钮禁用、默认选中的三种写法并通过js实现(重点)
案例演示:演示个人信息注册案例(历时20分钟)
总结:对DOM操作做总结(历时5分钟)
- html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>对表单元素的属性操作title>
- <style>
- .imgB {
- margin-top: 200px;
- }
-
- .select {
- width: 1000px;
- height: 600px;
- }
-
- #box {
- height: 100px;
- background-color: crimson;
- }
- style>
- head>
-
- <body>
- <input type="button" value="显示图片" id="show">
- <input type="button" value="改变图片的尺寸" id="change">
- <input type="button" value="隐藏图片" id="hide">
- <div>
- <img src="" alt="" id="imgBox" style="border: 10px solid black;" class="imgB">
- div>
- <div id="box">我是divdiv>
- <p>检测图片是否占位置p>
- body>
- <script>
- var showBtn = document.querySelector("#show");
- var changeBtn = document.querySelector("#change");
- var hideBtn = document.querySelector("#hide");
- var imgBox = document.querySelector("#imgBox");
- var box = document.getElementById("box");
- // 显示
- showBtn.onclick = function () {
- imgBox.src = "images/yang.jpeg"
- }
- // 改变尺寸
- changeBtn.onclick = function () {
- //1、直接修改宽高属性
- /* imgBox.width = "1000";
- imgBox.height = "600"; */
- // 2、style
- // imgBox.style = "width: 1000px;height: 600px;";
- /* imgBox.style.width = "1000px";
- imgBox.style.height = "1000px"; */
- // 3。类名
- imgBox.className = "select";
- // CSS中用链接符的属性,在js中去掉链接符且第二个单词的首字母大写
- box.style.backgroundColor = "blue";
- box.style.color = "red";
- box.style.fontSize = "30px";
- box.style.width = "300px";
- box.style.marginTop = "100px";
- box.style.textAlign = "center";
- }
- // 隐藏
- hideBtn.onclick = function () {
- // imgBox.style.display = "none";
- imgBox.style.visibility = "hidden";
-
- }
- script>
-
- html>