• DOM对非表单元素与表单元素的属性操作


    本课标题: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分钟

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>对表单元素的属性操作title>
    8. <style>
    9. .imgB {
    10. margin-top: 200px;
    11. }
    12. .select {
    13. width: 1000px;
    14. height: 600px;
    15. }
    16. #box {
    17. height: 100px;
    18. background-color: crimson;
    19. }
    20. style>
    21. head>
    22. <body>
    23. <input type="button" value="显示图片" id="show">
    24. <input type="button" value="改变图片的尺寸" id="change">
    25. <input type="button" value="隐藏图片" id="hide">
    26. <div>
    27. <img src="" alt="" id="imgBox" style="border: 10px solid black;" class="imgB">
    28. div>
    29. <div id="box">我是divdiv>
    30. <p>检测图片是否占位置p>
    31. body>
    32. <script>
    33. var showBtn = document.querySelector("#show");
    34. var changeBtn = document.querySelector("#change");
    35. var hideBtn = document.querySelector("#hide");
    36. var imgBox = document.querySelector("#imgBox");
    37. var box = document.getElementById("box");
    38. // 显示
    39. showBtn.onclick = function () {
    40. imgBox.src = "images/yang.jpeg"
    41. }
    42. // 改变尺寸
    43. changeBtn.onclick = function () {
    44. //1、直接修改宽高属性
    45. /* imgBox.width = "1000";
    46. imgBox.height = "600"; */
    47. // 2、style
    48. // imgBox.style = "width: 1000px;height: 600px;";
    49. /* imgBox.style.width = "1000px";
    50. imgBox.style.height = "1000px"; */
    51. // 3。类名
    52. imgBox.className = "select";
    53. // CSS中用链接符的属性,在js中去掉链接符且第二个单词的首字母大写
    54. box.style.backgroundColor = "blue";
    55. box.style.color = "red";
    56. box.style.fontSize = "30px";
    57. box.style.width = "300px";
    58. box.style.marginTop = "100px";
    59. box.style.textAlign = "center";
    60. }
    61. // 隐藏
    62. hideBtn.onclick = function () {
    63. // imgBox.style.display = "none";
    64. imgBox.style.visibility = "hidden";
    65. }
    66. script>
    67. html>

  • 相关阅读:
    基本分段存储管理方式(分段,段表,地址转换以及与分页管理对比)
    CentOS7安装jdk
    机器学习笔记之线性分类——逻辑回归
    (二)springboot整合redis,基于注解快速实现缓存功能
    bootstrapv4轮播图去除两侧阴影及线框的方法
    【实验作业】微处理器原理与应用 CPUHomework3【子程序汇编实验 流程图 十六进制数转十进制数 键盘录入 屏幕显示 闰年判断 两位数求和 汇编小程序】
    驱动按键控制led
    25 个超棒的 Python 脚本合集
    Nacos安装讲解教程
    PostgreSQL基础入门
  • 原文地址:https://blog.csdn.net/weixin_47619284/article/details/126276683