innerHTML and outerHTML是什么?
innerHTML:得出调用该方法的节点下的HTML代码,但不包括该节点本身的HTML代码
outerHTML:得出调用该方法的节点及该节点下的HTML代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script type="text/javascript">
function getinnerHTML()
{
var e=window.document.getElementById("try");
alert(e.innerHTML);
}
function getouterHTML()
{
var e=window.document.getElementById("try");
alert(e.outerHTML);
}
</script>
</head>
<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="try">
<tr>
<td>点击下面按钮获得表格的innerHTML各outerHTML</td>
</tr>
</table>
<p>
<input type="button" name="Submit2" value="innerHTML" onClick="getinnerHTML()">
<input type="button" name="Submit" value="outerHTML" onClick="getouterHTML()">
</p>
</body>
</html>
outerHTML:得出调用该方法的节点及该节点下的HTML代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script type="text/javascript">
function getinnerHTML()
{
var e=window.document.getElementById("try");
alert(e.innerHTML);
}
function getouterHTML()
{
var e=window.document.getElementById("try");
alert(e.outerHTML);
}
</script>
</head>
<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="try">
<tr>
<td>点击下面按钮获得表格的innerHTML各outerHTML</td>
</tr>
</table>
<p>
<input type="button" name="Submit2" value="innerHTML" onClick="getinnerHTML()">
<input type="button" name="Submit" value="outerHTML" onClick="getouterHTML()">
</p>
</body>
</html>