返回到:Prototype – 元素对象
此方法在元素之前、之后、顶部或底部插入内容,由第二个参数的 position 属性指定。如果第二个参数是内容本身,insert 会将其附加到元素。
插入接受以下类型的内容 –
- 文本
- HTML
- DOM元素
- 具有 toHTML 或 toElement 方法的任何类型的对象。
注意– 请注意,如果插入的 HTML 包含任何 <script> 标记,这些将在插入后自动评估。
语法
element.insert({ position: content });
OR
element.insert(content)
返回值
插入内容后返回 HTML 元素。
例子
HTML
x
25
25
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
var str = $('apple').insert( "<li>mangoes</li>" );
9
alert(str.innerHTML );
10
}
11
</script>
12
</head>
13
14
<body>
15
<p>Click the button to see the result.</p>
16
17
<ul>
18
<li id = "apple">apple</li>
19
<li>orange</li>
20
</ul>
21
<br />
22
23
<input type = "button" value = "Click" onclick = "showResult();"/>
24
</body>
25
</html>
返回到:Prototype – 元素对象
阅读剩余 47%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9083.html