js控制div及網(wǎng)頁相關(guān)屬性的代碼
動態(tài)創(chuàng)建DIV:var div = document.createElement("div");
設(shè)置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添加到body:document.body.appendChild(div );
設(shè)置Attribute屬性:
添加,設(shè)置:
(1). div.setAttribute("ok","ok?");
html: <div id="id" style="background-color: red;" ok="ok?"/>
(2). var ok = document.createAttribute("name");
div.setAttributeNode(ok);
html: <div id="id" style="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);//ok為AttributeNode對象。
很重要的一個方法
document.getElementsByTagName
相關(guān)文章
Javascript設(shè)計模式之觀察者模式的多個實現(xiàn)版本實例
這篇文章主要介紹了Javascript設(shè)計模式之觀察者模式的多個實現(xiàn)版本實例,本文給出3種實現(xiàn)版本代碼,同時給出了Jquery實現(xiàn)版本,需要的朋友可以參考下2015-03-03
讓html元素隨瀏覽器的大小自適應(yīng)垂直居中的實現(xiàn)方法
下面小編就為大家?guī)硪黄宧tml元素隨瀏覽器的大小自適應(yīng)垂直居中的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10
淺談html轉(zhuǎn)義及防止javascript注入攻擊的方法
下面小編就為大家?guī)硪黄獪\談html轉(zhuǎn)義及防止javascript注入攻擊的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12

