zoukankan      html  css  js  c++  java
  • 原生态js获取节点的方法

    <input value="我是用id来获取值的" type="button" onclick="GetById()"/>
    <input value="我是用Name来获取值的" type="button" onclick="GetByName()"/>
    <input value="我是用tagName来获取值的" type="button" onclick="GetByTagName()"/>
    <div id="divid" name="divName">我是用来测试的div</div>
    <script type="text/javascript">
        function GetById() {
            var a = document.getElementById("divid");
            alert(a.nodeName + "," + a.nodeType + "," + a.nodeValue);
            var text = a.innerHTML;
            alert(text);
            //1、给字体设置颜色
          //  a.innerHTML = "现在已经改了".fontcolor("red");
            //2、给div设置样式
            a.style.width="500px";
            a.style.height="300px";
            a.style.border="1px solid red";
        }
        function GetByName() {
            var b = document.getElementsByName("divName");
            alert(b.nodeName);
            alert(b[0].nodeName + "-" + b[0].nodeType + "-" + b[0].nodeValue);
        }
        function GetByTagName() {
            var c = document.getElementsByTagName("div");
            alert(c.nodeName);
            alert(c[0].nodeName + "-" + c[0].nodeType + "-" + c[0].nodeValue);
        }
    </script>
  • 相关阅读:
    jqurey技术总结
    ie浏览器兼容问题小结
    FIS的合并压缩技术
    对js中数组的一些总结
    浅谈如何面向对象进行封装
    13th week blog
    12th week blog
    11th week blog
    10th week blog
    9th Week blog
  • 原文地址:https://www.cnblogs.com/superMay/p/4876967.html
Copyright © 2011-2022 走看看