原型 - update() 方法
此方法用給定的 newContent 引數替換元素內容,並返回該元素。
提供的 newContent 可以是純文字、HTML 片段或具有 toString() 方法的任何 JavaScript 物件。如果它包含任何 <script> 標記,這些標記將元素更新後進行評估。
如果沒有提供引數,Element.update 只會清除其內容。
語法
element.update( newContent );
返回值
更新的 HTML 元素。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
$('movies').update("Spider Man, USV-315");
}
</script>
</head>
<body>
<p>Click the button to see the result</p>
<div id = "movies">
Speed, Titanic, Brave Heart
</div>
<input type = "button" value = "Click" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_element_object.htm
廣告