-3
当任何链接被点击的文本(不点击)应由及时更换。
<div><a href="http://facebook.com">Facebook(NOT CLICKED)</a></div> <div> <ul> <li><a href="http://youtube.com">Youtube(NOT CLICKED)</a></li> </ul>
当任何链接被点击的文本(不点击)应由及时更换。
<div><a href="http://facebook.com">Facebook(NOT CLICKED)</a></div>
<div>
<ul>
<li><a href="http://youtube.com">Youtube(NOT CLICKED)</a></li>
</ul>
var links = document.querySelectorAll("a");
links.forEach(function(l) {
l.addEventListener("click", clickHandler);
});
function clickHandler(ev) {
ev.preventDefault(); // don't redirect (don't go the the link in the href)
this.textContent = this.textContent.replace("(NOT CLICKED)", "(" + Date() + ")"); // replace the text "(NOT CLICKED)" with "(date)"
}
<div><a href="http://facebook.com">Facebook(NOT CLICKED)</a></div>
<div>
<ul>
<li><a href="http://youtube.com">Youtube(NOT CLICKED)</a></li>
</ul>
</div>
发表一些你的HTML不是链接到Facebook和YouTube! –
@ibrahimmahrir我已更新它 –
如果点击链接,您将被重定向,任何更改都将丢失!你想防止点击的默认行为? –