<!DOCTYPE html>
<html>
<body>
<p id="intro">Hello World!</p>
<p>本例演示 <b>getElementById</b> 方法的使用方法:</p>
<script>
document.write("</br>");
x=document.getElementById("intro");
document.write("<p>getElementById Return Value is:" + x + "</p>");
document.write("<p>getElementById Return Value's NodeName’:" + x.nodeName + "</p>");
document.write("<p>getElementById Return Value's NodeValue’:" + x.nodeValue + "</p>");
document.write("</br>");
document.write("<p>getElementById Return Value's childNode's NodeValue is:" + x.firstChild.nodeValue + "</p>");
document.write("<p>Id为intro段落的文本值为:" + x.innerHTML + "</p>");
</script>
</body>
</html>
运行结果:
Hello World!
本例演示 getElementById 方法的使用方法:
getElementById Return Value is:[object HTMLParagraphElement]
getElementById Return Value's NodeName’:P
getElementById Return Value's NodeValue’:null
getElementById Return Value's childNode's NodeValue is:Hello World!
Id为intro段落的文本值为:Hello World!