js動態(tài)創(chuàng)建及移除div的方法
更新時間:2015年06月03日 16:25:42 作者:誠實的丑小鴨
這篇文章主要介紹了js動態(tài)創(chuàng)建及移除div的方法,涉及javascript針對頁面元素的動態(tài)操作技巧,需要的朋友可以參考下
本文實例講述了js動態(tài)創(chuàng)建及移除div的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
//創(chuàng)建div function createDiv(){ if(document.getElementByIdx_x("newD")!=null) document.body.removeChild(document.getElementByIdx_x("newD")); var Div = document.create_rElement("div");//創(chuàng)建div Div.setAttribute("id", "newD"); Div.style.position = "absolute"; Div.style.height = "160px"; Div.style.width = "400px"; Div.style.border = "1px solid grey"; Div.style.background = "white"; Div.style.paddingTop = "40px"; Div.style.zIndex = "100"; Div.style.left = 100 +"px";//注意Firefox下必須加"px" Div.style.top = 100 +"px"; Div.style.textAlign = "center"; Div.style.fontSize = "18px"; var str = "<div id=\"divClose\" onclick=\"removeDiv()\" style=\"width:16px;height:16px;float:right;margin-top:-40px;background:url(images/divClose.gif);\"><\/div>"; Div.innerHTML = str + title; document.body.appendChild(newD); } //移除創(chuàng)建的div function removeDiv(){ document.body.removeChild(document.getElementByIdx_x_x("newD")); }
希望本文所述對大家的javascript程序設計有所幫助。
您可能感興趣的文章:
- js 動態(tài)創(chuàng)建 html元素
- js實現(xiàn)動態(tài)創(chuàng)建的元素綁定事件
- JS使用eval()動態(tài)創(chuàng)建變量的方法
- JS動態(tài)創(chuàng)建元素的兩種方法
- 動態(tài)創(chuàng)建按鈕的JavaScript代碼
- JavaScript如何動態(tài)創(chuàng)建table表格
- JS動態(tài)創(chuàng)建DOM元素的方法
- javascript實現(xiàn)dom動態(tài)創(chuàng)建省市縱向列表菜單的方法
- jQuery動態(tài)創(chuàng)建html元素的常用方法匯總
- jquery 動態(tài)創(chuàng)建元素的方式介紹及應用
- 基于jquery的動態(tài)創(chuàng)建表格的插件
- javascript與jquery動態(tài)創(chuàng)建html元素示例
相關文章
JS實現(xiàn)簡單的星期格式轉(zhuǎn)換功能示例
這篇文章主要介紹了JS實現(xiàn)簡單的星期格式轉(zhuǎn)換功能,涉及JavaScript基于Date()對象的日期時間操作技巧,需要的朋友可以參考下2018-07-07JavaScript中如何在一個循環(huán)中等待示例代碼詳解
這篇文章主要介紹了在JavaScript中如何在一個循環(huán)中等待(附代碼示例),下面是如何使用for..of 循環(huán)來迭代一個數(shù)組并在循環(huán)內(nèi)等待,需要的朋友可以參考下2022-08-08List all the Databases on a SQL Server
List all the Databases on a SQL Server...2007-06-06JavaScript代碼調(diào)試方法實例小結(jié)
這篇文章主要介紹了JavaScript代碼調(diào)試方法,結(jié)合實例形式總結(jié)分析了JavaScript錯誤信息的處理與代碼調(diào)試相關操作技巧,需要的朋友可以參考下2019-01-01