✍ 📁 🙈 🙉 🙊
HTML
window Resize
html 測試 左入右出
html 測試 上入下出
html 測試 單入單出
html 測試 左單右單
顯示具有
script 元素替換 replaceChild()
標籤的文章。
顯示所有文章
顯示具有
script 元素替換 replaceChild()
標籤的文章。
顯示所有文章
createElement()
createElement() 創建元素
<pre><b>createElement() 創建元素</b> document.createElement() 創建一個元素。 例 : document.createElement("div") document.createElement("P") document.createElement("input") .......等等 document.createElement() 可以建立一個新的元素。 document.createTextNode() 就是用來建立文字節點的方法。 document.createDocumentFragment() 一開始我們有一個 HTML 的容器元素。 Node.appendChild() 方法在節點的子節點<r>列表末</r>新增新的子節點。 Node.insertBefore() 方法在節點的子節點列表任意位置<r>插入</r>新的節點。 Node.removeChild() 方法從 DOM 移除一個子節點,並返回<r>移除</r>的節點。 Node.replaceChild() 實現子節點(對像)的替換。返回被<r>替換</r>對像的引用。 Node.hasChildNodes() 取得值,指出這個節點<r>是否有子節點</r>。 </pre> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
<b>Node.appendChild( )<br> 用來新增一個子節點到指定元素節點的最後面</b> <pre> Node.appendChild(child) : child 為另一個元素物件。 var newDiv = document.createElement("div"); var newT = document.createTextNode("<<?>div>New div<<?>/div>"); newDiv.appendChild(newT); <r>document.body</r>.appendChild(newDiv, div1); //<r>document.body</r> 內加入新 div </pre> <button onclick="myFunction()">Node.appendChild()</button> <div id="DP"> <div id="div1" ><<?>div id="div1"><<?>/div></div> </div> <script> function myFunction() { var newDiv = document.createElement("div"); var newContent = document.createTextNode("<div>New div</div>"); newDiv.appendChild(newContent); document.body.appendChild(newDiv, div1); } </script> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
<b>Node.appendChild( )<br> 用來新增一個子節點到指定元素節點的最後面</b> <pre> var newDiv = document.createElement("div"); var newContent = document.createTextNode("Hi"); newDiv.appendChild(newContent); <r>div1</r>.appendChild(newDiv, div1); //<r>div1</r> 內加入新 div </pre> <button onclick="myFunction()">Node.appendChild()</button> <div id="div1" ><<c>div id="<r>div1</r>"> </div> <<c>/div> <script> function myFunction() { var newDiv = document.createElement("div"); var newContent = document.createTextNode("Hi"); newDiv.appendChild(newContent); div1.appendChild(newDiv, div1); } </script> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
<b>Node.insertBefore()<br> 插入新的子代 (child) 元素。</b> <pre> parentNode.insertBefore(插入的新元素, 之前的元素物件); <<c>ol id="myList"> <<c>li>Coffee<<c>/li> <<c>li>Tea<<c>/li> <<c>/ol> var newNode = document.createElement("li"); var textNode = document.createTextNode("new li"); newNode.appendChild(textNode); myList.insertBefore(newNode, myList.children[1]); </pre> <button onclick="myFunction()">insertBefore()</button> <ol id="myList"> <li>Coffee</li> <li>Tea</li> </ol> <script> function myFunction() { var newNode = document.createElement("li"); var textNode = document.createTextNode("new li"); newNode.appendChild(textNode); myList.insertBefore(newNode, myList.children[1]); } </script> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
<b>Node.removeChild() <br> 移除一個子節點,並傳回移除的節點。</b> <pre><<?>div id="Mid"> <<?>button onclick="remove(this)"> 1 remove me <<?>/button> <<?>button onclick="remove(this)"> 2 remove me <<?>/button> <<?>button onclick="remove(this)"> 3 remove me <<?>/button> <<?>button onclick="remove(this)"> 4 remove me <<?>/button> <<?>button onclick="remove(this)"> 5 remove me <<?>/button> <<?>/div> <<c>script> function remove(x) { Mid.removeChild(x) } <<c>/script> </pre> <div id="Mid"> <button onclick="remove(this)"> 1 remove me </button> <button onclick="remove(this)"> 2 remove me </button> <button onclick="remove(this)"> 3 remove me </button> <button onclick="remove(this)"> 4 remove me </button> <button onclick="remove(this)"> 5 remove me </button> </div> <script> function remove(x) { Mid.removeChild(x) } </script> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
<B>node.replaceChild( newChild, oldChild )<br> 取代 元素 </B> <pre> newChild 為要加進去的子代元素, oldChild 為要換掉的的子代元素。 例: <<?>input id="input_DP" type="text" value="input tag" /> var textarea =document.createElement('textarea') ; textarea.innerHTML = "textarea tag"; textarea.id="textarea_ID" ; input_DP.parentNode.replaceChild(textarea , input_DP) </pre> <table border="1" style="width:100%"> <tbody> <tr><td width="50%" height="80px"> <input id="DP" type="text" value="input tag" /> </td><td> <button id="B4" onclick="Replace()" title="B4">換掉元素</button> </td></tr></tbody></table> <script> function Replace() { if( DP.nodeName=="INPUT"){ var textarea =document.createElement('textarea') ; textarea.innerHTML = "textarea tag"; textarea.id="DP" ; DP.parentNode.replaceChild(textarea , DP) ; return } var input =document.createElement('input') ; input.value = "input tag" ; input.id="DP" ; DP.parentNode.replaceChild(input, DP) ; } </script> <style> #Mdiv {display:none} input:focus {background-color: yellow} input {background-color: lime } pre { font-size: 20px ; white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } b{font-size:30px;color:blue;} r{font-size:20px;color:red; } #B4 { height:30px ; width:100px ; font-size: 16px ; cursor: pointer ; color: black; background-color: lightgray ; border-radius: 8px ; box-shadow: 4px 4px #999 ;} #B4:hover { background-color: gainsboro ;} #B4:active { background-color: darkgray ; box-shadow: 1px 1px #666 ; transform: translate(4px,4px) ;} </style>
預覽
寫程式
還原
LLLLLLLLLLLLLLLLL
Edit
#html
#網頁格式
#style
#div
#createElement() 創建元素
#Node.removeChild()
#Node.insertBefore()
#Node.appendChild( )
#createElement()
較舊的文章
首頁
訂閱:
文章 (Atom)