国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript動態創建div等元素實例講解

2019-11-20 10:50:56
字體:
來源:轉載
供稿:網友

本文實例講解了JavaScript動態創建div等元素的詳細代碼,分享給大家供大家參考,具體內容如下

效果圖:

為了節省時間,就直接貼代碼了!

<html>   <head>   <title>js動態創建div等元素實例</title>   <style type="text/css">   </style>   </head>   <body>   <script language="javascript">     var Test={       createDiv:function(){         var div = document.createElement('div');         div.id="createDiv";         div.style.cssText = 'border:1px solid red; width:200px; z-index:100; height:20px;';         document.body.appendChild(div);       },       appendDivChild:function(){         var div = document.createElement('div');         div.id="appendDivChild";         div.style.cssText = 'border:1px solid green; width:400px; z-index:100; height:100px;';         var childDiv= document.createElement('div');         childDiv.id="childDiv";         childDiv.style.cssText = 'border:2px solid gray; width:200px; z-index:100; height:50px;';         div.appendChild(childDiv);         document.body.appendChild(div);       },       createSelect:function(){         var select=document.createElement('select');         select.id="select";         var option1=document.createElement('option');         option1.value=1;         option1.text=1;//非ie,添加內容         option1.innerHTML=1;//ie,添加內容         select.appendChild(option1);         var option2=document.createElement('option');         option2.value=2;         option2.text=2;         option2.innerHTML=2;         select.appendChild(option2);         var option3=document.createElement('option');         option3.value=3;         option3.text=1;         option3.innerHTML=3;         select.appendChild(option3);         document.body.appendChild(select);       },       createRadio:function(){         var radio=document.createElement('input');         radio.id='radio';         radio.type="radio";         radio.width="100";         var label=document.createElement('label');         label.text="男";         label.innerHTML="男";         document.body.appendChild(radio);         document.body.appendChild(label);       }     };     Test.createDiv();//創建div     Test.appendDivChild();//為追加子div     Test.createSelect();//創建下拉框     Test.createRadio();//創建單選按鈕   </script>   <select>     <option>1</option>     <option>2</option>     <option>3</option>   </select>   </body> </html> 

希望本文所述對大家學習javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泉州市| 临潭县| 禄丰县| 清水河县| 黔江区| 旬阳县| 古丈县| 建瓯市| 芦山县| 维西| 绥滨县| 平舆县| 正阳县| 全南县| 方山县| 安图县| 上栗县| 二连浩特市| 安仁县| 临安市| 万山特区| 郑州市| 桃园县| 长春市| 徐闻县| 红河县| 尼勒克县| 延寿县| 融水| 绥芬河市| 建德市| 青河县| 弥勒县| 五指山市| 宁波市| 彭州市| 射阳县| 达州市| 琼中| 纳雍县| 新晃|