getElementByID、createElement、appendChild幾個DHTML元素第2/2頁
更新時間:2008年06月25日 21:17:24 作者:
WEB標(biāo)準(zhǔn)下可以通過getElementById(), getElementsByName(), and getElementsByTagName()訪問
appendChild方法的使用
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標(biāo)題文檔</title>
</head>
<script language="javascript">
//生成與輸入內(nèi)容匹配行
function setNames() {
completeBody = document.getElementById("complete_body");
var row, cell, txtNode;
//var nextNode = names[i].firstChild.data;
row = document.createElement("tr");
cell = document.createElement("td");
cell.setAttribute("bgcolor", "#FFFAFA");
cell.setAttribute("border", "0");
//txtNode = document.createTextNode(nextNode);
alert("sdf");
var newText = document.createTextNode("This is the second paragraph.");
//txtNode=document.createElement("div");
alert("sdf1");
cell.appendChild(newText);
alert("sdf2");
row.appendChild(cell);
completeBody.appendChild(row);
}
</script>
<body>
<input type="submit" name="sdf" onclick="setNames()">
<table id="complete_table" bgcolor="#FFFAFA" border="0"
cellspacing="0" cellpadding="0" />
<tbody id="complete_body"></tbody>
</table>
</body>
</html>
=================================
createElement
<html>
<head>
<title>createElement</title>
<script language="javascript">
<!--
var i=0 ;
function addInput() {
var o = document.createElement("input");
o.type = "button" ;
o.value = "按鈕" + i++ ;
o.attachEvent("onclick",addInput);
document.body.appendChild(o);
o = null;
}
//-->
</script>
</head>
<body onload="addInput();">
</body>
</html>
您可能感興趣的文章:
- 原生js操作checkbox用document.getElementById實現(xiàn)
- 一行代碼告別document.getElementById
- js querySelector和getElementById通過id獲取元素的區(qū)別
- getElementByIdx_x js自定義getElementById函數(shù)
- document.getElementById介紹
- document.getElementById方法在Firefox與IE中的區(qū)別
- document.getElementById為空或不是對象的解決方法
- document.getElementById獲取控件對象為空的解決方法
相關(guān)文章
小程序云開發(fā)如何實現(xiàn)圖片上傳及發(fā)表文字
這篇文章主要為大家詳細(xì)介紹了小程序云開發(fā)教程,如何實現(xiàn)圖片上傳及發(fā)表文字,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05
bootstrap折疊調(diào)用collapse()后data-parent不生效的快速解決辦法
今天做的項目,用到了bootstrap的折疊功能,這個功能需要只展開一個折疊框,點(diǎn)擊一個就會自動隱藏另一個,實現(xiàn)起來也很容易,但是在測試時同事提出了一個bug,怎么解決呢?今天小編通過本教程給大家分享下2017-02-02

