gpt4 book ai didi

javascript - 如何根据事件网址更改导航栏中的图像?

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:29 25 4
gpt4 key购买 nike

我想做的是在事件 url 为 index.html 时切换 #navbar-image-id2games。我尝试像这样使用 javascript 来执行此操作,但它似乎不起作用。

HTML:

<div class="navbar-item" id="navbar-item-ID2Games">
<a href="index.html" id="index-url">
<div class="navbar-image" id="navbar-image-unhovered">
</div>
<div class="navbar-image" id="navbar-image-id2games">
</div>

<br>

<div class="navbar-text">
ID2 Games
</div>
</a>
</div>

Javascript:

$('#index-url').active(function() {
$('#navbar-image-id2games').toggle();
$('#navbar-image-unhovered').hide();
});

JSFiddle: https://jsfiddle.net/zxsmuaae/

最佳答案

你可以通过以下方式检查用户是否在 index.html 中:

if (window.location.href.match(/index\.html/)) {
// toggle
}

关于javascript - 如何根据事件网址更改导航栏中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30294408/

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