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();             //标签选择器。

  • 相关阅读:
    程序员掌握的单词汇总
    Django--基础补充
    C#入门概述
    python常用模块
    软件开发经验之谈
    p7.BTC-挖矿总结
    p6.BTC-挖矿难度
    p5.BTC-网络
    p4.BTC-实现
    p3.BTC-协议
  • 原文地址:https://www.cnblogs.com/dej-11/p/7429561.html
Copyright © 2011-2022 走看看