gpt4 book ai didi

javascript - 使用不显眼的 JS 而不是 jQuery,用于导航的可访问更改菜单项,

转载 作者:太空宇宙 更新时间:2023-11-04 14:14:24 26 4
gpt4 key购买 nike

我现在感觉像个严肃的 id10t,但我花了一个星期的时间寻找一种语义的、可访问的、JavaScript 方法来保持链接上的事件样式,直到点击另一个链接.我希望它是非常基本的东西......

该站点是单个页面,使用 id/anchor 标记链接到页面上的各个部分。

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8" /></head>
<body>

<header>
<h1>Crown Cattle Company</h1>
<ol>
<li><a href="../index.html">(Temp Home)</a></li>
<li><a href="#farm">Orielton</a></li>
<li><a href="#genetics">Wagyu</a></li>
<li><a href="#cooking">Recipes</a></li>
</ol>
</header>

<main>
<article>

<section id="orielton">
<h2>Orielton</h2>
<nav><ul>
<li><a href="#farm">Crown Cattle Company</a></li>
<li><a href="#maps">Map</a></li>
<li><a href="#contact">Contact</a></li>
</ul></nav>
<p id="farm">CCC. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p id="map"><div id="map-canvas"></div></p>
<p id="contact">Contact. There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
</section>
</article>
</main>
</body>
</html>

源文件在这里:( http://www.crowncattle.com.au/html/content%20scroll.html#farm )

提前感谢您让我保持清醒。这让我头疼。干杯

最佳答案

在最新的浏览器中,我建议:

function lastLink(e){
e.preventDefault();
var _lastClicked = document.querySelector('a.lastActive');
if (_lastClicked) {
_lastClicked.classList.remove('lastActive');
}
this.classList.add('lastActive');
}

var links = document.querySelectorAll('a');

[].forEach.call(links, function(a){
a.addEventListener('click', lastLink);
});

JS Fiddle demo .

引用资料:

关于javascript - 使用不显眼的 JS 而不是 jQuery,用于导航的可访问更改菜单项,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20470556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com