• JavaScript class css样式 DOM Tree


    ----------------------------class-------------------------------

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    .bigger{
    font-size: 34px;
    }
    </style>
    </head>
    <body>

    <div class="div1 div2 bigger" id="ID">
    hello
    <div>hello2</div>
    <p>hello p</p>
    </div>

    <script>
    var ele=document.getElementById("ID");
    // alert(ele.className)
    // ele.classList.add("bigger")
    ele.classList.remove("bigger");
    </script>
    </body>
    </html>

    ----------------------CSS样式------------------------------

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    .bigger{
    font-size: 40px;
    color: #84a42b;
    }
    .small{
    font-size: 10px;
    color: rebeccapurple;
    }

    </style>
    </head>
    <body>

    <div id="div1">fhslajkdfhsdjfsdasadfhlakjsdfhkjl</div>
    <input type="button" onclick="change('bigger')" value="big">
    <input type="button" onclick="change('small')" value="small">

    <script>
    function change(a) {
    var ele=document.getElementById("div1");

    ele.classList.add(a);

    }


    </script>

    </body>
    </html>

    ------------------------DOM Tree-------------------------

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Title</title>
    </head>
    <body>
    <div id="div1">
    <div>hello div </div>
    <p>hello p</p>
    </div>

    <script>

    var ele=document.getElementById("div1");
    var ele2=ele.firstChild;
    alert(ele2.nodeName);
    var ele3=ele.lastChild;
    alert(ele3.nodeName);

    var ele3=ele.childNodes;
    alert(ele3.length);

    var ele3=ele.parentNode;
    alert(ele3.nodeName);


    console.log(ele.nodeName);
    console.log(ele.nodeType);
    console.log(ele.nodeValue);

    // 推荐方式
    var ele=document.getElementById("div1");
    var ele_son=ele.firstElementChild;
    alert(ele_son.nodeName)

    var ele_son=ele.lastElementChild;
    alert(ele_son.nodeName);
    var ele_sons=ele.children;
    alert(ele_sons.length);
    alert(ele_sons[0]);

    for (var i=0;i<ele_sons.length;i++){
    console.log(ele_sons[i])
    }


    var ele=document.getElementById("div1").firstElementChild;
    var sib=ele.nextElementSibling;
    alert(sib.nodeName);


    //这些属性是为了对文档树进行导航;

    </script>
    </body>
    </html>

  • 相关阅读:
    ArcGIS 10.1 如何连接数据库(转载)
    silverlight generic.xaml 包含中文 编译错误的问题
    WPF XAML之bing使用StringFormat (转)
    geoserver 知识小计
    [100天计划][1/15][1/30]开篇清单
    工作总结,给个公式,发发牢骚,继续得过
    值类型与引用类型(特殊的string) Typeof和GetType() 静态和非静态使用 参数传递 相关知识
    跑步之后的胡思乱想
    Linq To DataSet
    近期专案PM相关收获
  • 原文地址:https://www.cnblogs.com/gerenboke/p/11767240.html
Copyright © 2020-2023  润新知