我正在开发一个Firefox扩展,用于修改加载的网页的内容。首先,我选择“src”或“href”属性与我的正则表达式匹配的所有元素(代码的这部分工作)。在任何DOM元素旁边插入徽标
然后,我想在使用下面的代码中发现了元素的父的右上角放置一个小图片:
/* create and add attributes to image */
var img = window.content.document.createElement("img");
var b = window.content.document.createAttribute("src");
b.nodeValue = "chrome://plugin/content/agent.png";
img.setAttributeNode(b);
img.addEventListener("click", function(){ alert("ds"); });
img.style.display = "block";
img.style.border = "3px solid red";
img.style.position = "relative";
img.style.top = "-10px";
img.style.right = "-10px";
img.style.left = "20px";
// ...代码返回元素...
//now insert the image
$jq(img).appendTo(element.parentNode);
当前的结果是,图片只显示在元素父级的底部或根本没有显示。
如果你看看这个:http://jsfiddle.net/yzwh5/64/ - 我希望我的按钮能以类似于红十字的方式工作。
这是我用这么多的解决方案之一。我修改了你的建议,但仍然没有喜悦。任何其他建议/解决方案如何解决这个问题? – 2012-04-04 15:25:19