• 网页 JavaScript的DOM操作


      今天,我首先对之前学习的内容进行了复习,然后学习了当鼠标指向某一个按钮时,切换对应的背景图片。

      <div id="d1">
      </div>
      <input type="button" value="1" onmouseover="dj1()" id="j1" class="c1" style="background-color:#6F3"/>
      <input type="button" value="2" onmouseover="dj2()" id="j2" class="c1"/>
      <input type="button" value="3" onmouseover="dj3()" id="j3" class="c1"/>

      

    <script>
      var a=document.getElementById("j1");
      var b=document.getElementById("j2");
      var c=document.getElementById("j3");
      function dj1()
      {
        var aa=document.getElementById("d1");
        aa.style.backgroundImage="url(6UPCKHIN3K5O0006.jpg)";
        a.style.backgroundColor="#6F3";
        b.style.backgroundColor="#CCC";
        c.style.backgroundColor="#CCC";
      }
      function dj2()
      {
        var aa=document.getElementById("d1");
        aa.style.backgroundImage="url(22.jpg)";
        a.style.backgroundColor="#CCC";
        b.style.backgroundColor="#6F3";
        c.style.backgroundColor="#CCC";
      }
      function dj3()
      {
        var aa=document.getElementById("d1");
        aa.style.backgroundImage="url(002-1.jpg)";
        a.style.backgroundColor="#CCC";
        b.style.backgroundColor="#CCC";
        c.style.backgroundColor="#6F3";
      }
    </script>

      之后,我学习了利用Window.document操作内容、样式和属性。

      alert(a.innerHTML);标签里的html代码和文字都获取了

      a.setAttribute("属性名","属性值");设置一个属性,添加或更改都可以;

      a.getAttribute("属性名");获取属性的值;

      a.removeAttribute("属性名");移除一个属性;

  • 相关阅读:
    Git原理与命令大全
    【网络安全】加解密算法最详解
    陪你阅读《区块链:从数字货币到信用社会》序一
    Splunk初识
    红帽学习记录[RHCE] ISCSI远程块储存
    DNS 域名系统与邮件服务器
    红帽学习记录[RHCE] 防火墙与网络合作
    红帽学习笔记[RHCE]网络配置与路由转发
    红帽学习笔记[RHCE]OpenLDAP 服务端与客户端配置
    红帽学习笔记[RHCSA] 第二周
  • 原文地址:https://www.cnblogs.com/hongsen3/p/5777166.html
Copyright © 2020-2023  润新知