zoukankan      html  css  js  c++  java
  • js控制div及相关属性

    动态创建DIVvar div = document.createElement("div"); 

    设置div属性及样式等:

    div.title="this is a new div."; 

           div.class = "newDivClass";   

      div.innerHTML = "Test create a div element!";

    div.style.styleFloat="left"; 
    div.style.overflow="hidden"; 
    div.style.marginLeft="8px"; 
    div.style.marginTop="10px"; 
    div.style.width="320px"; 
    div.style.height="250px"; 
    div.style.backgroundRepeat="no-repeat"; 

    div.style.backgroundImage="url(image/bgred.jpg)"  

    DIV添加到bodydocument.body.appendChild(div );

    设置Attribute属性:  

    添加,设置:

    (1).       div.setAttribute("ok","ok?");

    html:  <div id="idstyle="background-color: red;ok="ok?"/>

    (2).       var ok = document.createAttribute("name");

    div.setAttributeNode(ok);

    html:  <div id="idstyle="background-color: red;name=""/>

    获取:

    (1).div.getAttribute("ok");//ok?

    (2)var v = div.getAttributeNode("ok").value;// div.getAttributeNode("ok")获取的是//AttributeNode对象。

    删除

    (1).document.getElementById("id").removeAttribute("ok");//ok为属性名。

    (2).document.getElementById("id").removeAttributeNode(ok);//okAttributeNode对象。

  • 相关阅读:
    Java中的pom.xml
    Java中request请求配置
    java,名称工具类。手机号加星。
    Java数据库查询与循环处理
    php接口分页
    java中sql映射机制
    java中的model映射
    Java启动项目
    httpSession.removeAttribute 移除header中的属性
    mybatisplus 查询数据
  • 原文地址:https://www.cnblogs.com/langlang/p/1627055.html
Copyright © 2011-2022 走看看