返回到:Prototype – 元素对象
此方法用 html 参数的内容替换元素并返回删除的元素。
语法
element.replace(html);
这里的html可以是纯文本、HTML 片段或任何具有 toString() 方法的 JavaScript 对象。
如果它包含任何 <script> 标记,这些将在元素被替换后进行评估。
注意– 如果没有提供参数,Element.replace 将简单地清除其内容的元素。
返回值
返回移除的 HTML 元素。
例子
HTML
x
28
28
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
$('first').replace('<ul id = "favorite">' +
9
'<li>kiwi</li>' +
10
'<li>banana</li>' +
11
'<li>apple</li>' +
12
'</ul>');
13
}
14
</script>
15
</head>
16
17
<body">
18
<p id = "test">Click the button to see the result.</p>
19
20
<div id = "food">
21
<div id = "fruits">
22
<p id = "first">Kiwi, banana <em>and</em> apple.</p>
23
</div>
24
</div>
25
26
<input type = "button" value = "Click" onclick = "showResult();"/>
27
</body>
28
</html>
返回到:Prototype – 元素对象
阅读剩余 46%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9017.html