日期:2014-05-16 浏览次数:20494 次
<html>
<body>
<div id="myid">
test
</div>
<script language="javascript">
alert(document.getElementById("myid").innerHTML);
</script>
</body>
</html>
<html>
<head>
<script>
function test() {
testall=document.getElementsByTagName("body");
testbody=testall.item(0); //获得所有tagName是body的元素(当然每个页面只有一个)
testall=testbody.getElementsByTagName("p");// 获得body子元素种的所有P元素
testnode=testall.item(1); // 获得第二个P元素
alert(testnode.firstChild.nodeValue); //显示这个元素的文本
}
</script>
</head>
<body>
<p>hi</p>
<p>hello</p>
<script language="javascript">
test();
</script>
</body>
</html>
<html>
<body>
<head>
</head>
<div id="test"></div>
<script type="text/javascript">
var newdiv=document.createElement("div")
var newtext=document.createTextNode("A new div")
newdiv.appendChild(newtext)
document.getElementById("test").appendChild(newdiv)
</script>
</body>
</html>
<html>
<body>
<div id="parent"><div id="child">A child</div></div>
<script language="javascript">
var childnode=document.getElementById("child")
var removednode=document.getElementById("parent").removeChild(childnode)
</script>
</body>
</html>
<html>
<body>
<p id="mynode">test</p>
<script language="javascript">
p=document.getElementById("mynode")
pclone = p.cloneNode(true);
p.parentNode.appendChild(pclone);
</script>
</body>
</html>
<html>
<body>
<div id="mynode2">
<span id="orispan">span</span>
</div>
<script language="javascript">
var orinode=document.getElementById("orispan");
var newnode=document.createElement("p");
var text=document.createTextNode("test ppp ");
newnode.appendChild(text);
document.getElementById("mynode2").replaceChild(newnode, orinode);
</script>
</body>
</html>
<script type="text/javascript"></script>