页面导航: 首页网络编程JavaScript应用技巧 → 正文内容 js getElementByID、createElement、appendChild说明

getElementByID、createElement、appendChild几个DHTML元素第2/2页

发布:dxy 字体:[增加 减小] 类型:转载
WEB标准下可以通过getElementById(), getElementsByName(), and getElementsByTagName()访问

appendChild方法的使用
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="javascript">
//生成与输入内容匹配行
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>
当前2/2页 上一页12
浏览次数:载入中... 打印本文关闭本文返回首页
·在百度中搜索关于“getElementByID、createElement、appendChild几个DHTML元素相关内容

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行