我有这个隐藏的链路,这是需要用于其它目的:Javascript:如何更改子元素的属性?
<span id="notitle" style="display: none;">
<a href="...Foo" title="Foo" style="..."></a>
</span>
链路是动态生成的并自动包括标题属性。但是我想删除title属性,因为当用户复制粘贴周围的文本时会复制该值。
我想过使用JavaScript。这是我到目前为止:
<html>
<head>
<script type="text/javascript">
function notitle() {
var mylist=document.getElementById("notitle")
var listitems= mylist.getElementsByTagName("a")
for (i=0; i<listitems.length; i++) {
listitems.setAttribute("title", "");
}
}
</script>
</head>
<body onLoad="notitle()">
<p>Before hidden link:
<span id="notitle" style="display: none;">
<a href="#Foo" title="Foo">This Link should have no title attribute</a>
</span>
After hidden link.</p>
</body>
</html>
但是不起作用。我想这是关于listitems.setAttribute("title", "");
任何想法?欢呼:)
+1。你也可以使用['removeAttribute(“title”)'](https://developer.mozilla.org/en/DOM/element.removeAttribute) – 2010-06-21 10:09:55
就是这样。谢谢! – Martin 2010-06-21 10:14:33
这甚至更好。现在我看到它只是第一次运作,但不是像这样的链接。我将如何应用? – Martin 2010-06-21 10:25:55