zoukankan      html  css  js  c++  java
  • js 如何给标签增加属性

    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <div id="div1"></div>
    <div class="div2"></div>

    </body>
    </html>
    <script>

    var div1=document.getElementById("div1");                          //id选择器
    div1.innerHTML="我能<br/>干什么";
    // div1.innerText="我能<br/>干什么"; 不认<br/>
    // div1.innerText+="新增的内容";


    var div2=document.getElementsByClassName("div2")[0];      //class选择器
    div2.innerHTML="随便";
    div2.style.width="100px";
    div2.style.height="100px";
    div2.style.background="red";
    div2.setAttribute("hidden","hidden");
    div2.removeAttribute("hidden");


    // var div3=document.getElementsByName();
    // var div4=document.getElementsByTagName();             //标签选择器。

  • 相关阅读:
    百马百担
    穷举
    折叠次数
    判断年份是否是闰年
    定义xy比大小
    1月21日
    1月20日作业-第三题
    1月20日作业-第二题
    1月18日
    1月18日
  • 原文地址:https://www.cnblogs.com/dej-11/p/7429561.html
Copyright © 2011-2022 走看看