<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function getinnerHTML()
{
alert(document.getElementById("d").innerHTML)
}
function setinnerHTML()
{
document.getElementById("d").innerHTML="<div id=''d'' style=''background-color:#449966''>这是一个层,嘿嘿</div>"
}
function test()
{
var timevalue = new Date();
document.all.clock.innerText = timevalue.getYear() + "-" + (timevalue.getMonth()+1) + "-" + timevalue.getDay() + " " + timevalue.getHours() + ":" + timevalue.getMinutes();
}
</script>
</HEAD>
<BODY>
<div id="d" style="background-color:#ff9966">这是一个层</div>
<input type="button" value="获取innerHTML" onclick="getinnerHTML()">
<input type="button" value="设置innerHTML" onclick="setinnerHTML()">
<div id="clock">这是一个层</div>
<input type="button" value="获取innerText" Onclick="alert(clock.innerText)">
<input type="button" value="设置innerText" onclick="test()">
</BODY>
</HTML>
对于innerText,即把"<font color=blue>test</font>"当成整体内容显示出来。而对于innerHTML而言,则把"<font color=blue>test</font>"当成页面的一部分,即显示兰色的test字符 |