zoukankan      html  css  js  c++  java
  • DOM属性及创建标签

                    样式操作:
                        className
                        classList
                            classList.add
                            classList.remove
                            
                        <style>
                            .c1{
                                font-size:15px
                            }
                        </style>    
                        <div class='c1 c2'></div>
                        obj.style.font-size ='16px';
                    属性操作:
                        obj.setAttribute('xxxx','liunx')#添加属性
                        obj.removeAttribute('value')#移除属性
                        obj.attributes#获取所有属性
                    
                    创建标签,并添加到HTML中:
                        a.字符串形式
                        b.对象的方式
                            document.createElement('input');

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <input type="button" onclick="AddEle1();value='+'">
        <input type="button" onclick="AddEle2();value='+'">
    
        <div id="i1">
            <input type="text">
            <hr/>
        </div>
    
        <script>
            function AddEle1() {
                //创建一个标签
                //将标签添加到i1里面
                var tag= document.createElement('input');
                tag.setAttribute('type','text')
                tag.style.fontSize='22px'
                tag.style.color='red'
                // document.getElementById('i1').insertAdjacentHTML("beforeEnd",tag);
                document.getElementById('i1').appendChild(tag);
    
            }
            function AddEle2() {
                //创建一个标签
                //将标签添加到i1里面
                var tag="<input type='text'/><hr/>";
           //注意 第一个参数只能是 beforeEnd afterBegin beforeBegin afterEnd document.getElementById(
    'i1').insertAdjacentHTML("beforeEnd",tag); } </script> </body> </html>
  • 相关阅读:
    Git 几个常用操作
    Ubuntu16.04安装YouCompleteMe
    常用命令总结
    启动Kernel提示Bad Data CRC
    linux4.15.1编译init/mounts报错
    编译Linux-4.15.1内核时遇到:“error : openssl/bio.h :No such file or folder”
    添加mtdparts引起的问题
    arm-linux-ld:u-boot.lds:1: ignoring invalid character `#' in expression
    smartgit的安装
    ubuntu下安装wine
  • 原文地址:https://www.cnblogs.com/anhao-world/p/14282945.html
Copyright © 2011-2022 走看看