replace('new') 可以替换内容,如果没有参数提供,那么replace只是清除element的内容。当然,用remove会比它更加快速也更加标准。
实例如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="javascripts/prototype.js"></script>
</head>
<body>
<button onclick="$('first').replace('<strong>你好</strong>');">
点我一下看!
</button>
<div id="food">
<div id="fruits">
<p id="first">hello</p>
</div>
</div>
</body>
</html>
运行如下:
也可以使用如下代码实现:
<button onclick="$('first').innerHTML='<b>你好</b>';">
点我一下看!
</button>
<div id="food">
<div id="fruits">
<p id="first">hello</p>
</div>
</div>