首页 | 最近更改 | 编辑本页 | 较早版本

可打印版 | 免责声明

Not logged in
登录 | 帮助
 

Firefox:Dive Into Greasemonkey/4.10. Replacing an element with new content

Mozilla中文Wiki

您的位置:Dive Into Greasemonkey公用模式更新元素内容

4.10. 更新元素内容

如果您已经找到了一个元素,您就可以通过 replaceChild 函数来更新它的内容。

image:Permalink.gif 例子:更新图片的替代文本(假设页面上存在一个 ID="annoyingsmily" 的元素)

var theImage, altText;
theImage = document.getElementById('annoyingsmily');
if (theImage) {
    altText = document.createTextNode(theImage.alt);
    theImage.parentNode.replaceChild(altText, theImage);
}


Image:Note.png
如果您想用一大块 HTML 代码来更新元素内容, 您可以先将这些 HTML 代码构造为一个字符串,然后设置元素的 innerHTML 属性


实例

← 删除一个元素
快速插入 HTML →

取自"http://wiki.mozcn.org/index.php/Firefox:Dive_Into_Greasemonkey/4.10._Replacing_an_element_with_new_content"

本页面已经被浏览2141次。 最后更改13:43 2005年11月19日. 本站内容在创作共用署名-非商业用途-保持一致条款下发布。


[首页]
首页
最近更改
随机页面
新闻动态

编辑本页
讨论本页
较早版本
链入页面
链出更改

特殊页面
错误报告