需要帮助
单击任何链接时,文本(未单击)应替换为时间。
<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>
答案 0 :(得分:1)
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>