【发布时间】:2016-01-23 21:07:41
【问题描述】:
我创建了一个可直接点击的列表,但用户也应该能够使用前进和后退按钮在列表中循环。目前,我列出的项目确实将颜色变为红色。有没有办法使用 jQuery 让我在列表中前后移动?我查看了 Stack Overflow 并找到了使用数组的示例,但是我的列表会随着时间的推移而扩展,这似乎取消了使用数组来实现这一点。任何帮助都会很棒!
var Lst;
function changecolor(obj) {
if (Lst) Lst.style.color = "#663399";
obj.style.color = "red";
Lst = obj;
}
<!--shows hyperlink and targets iframe-->
(function() {
$('.menu a.nav-tab').on('click', function() {
var href = $(this).attr('href');
$('iframe').attr('src', href);
$('.current-url').empty().append($('<a>').attr('href', href).append('"' + href + '"'));
$('.menu a.nav-tab').removeClass('current');
$(this).addClass('current');
return false;
});
})();
* {
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
iframe {
width: 200px;
height: 100%;
}
.hyperlinks {
height: 25px;
width: 250px;
position: absolute;
left: 265px;
top: -4px;
background: #ffffff;
}
.current-url {
text-overflow: ellipsis;
width: 250px;
height: 15px;
overflow: hidden;
white-space: nowrap;
padding-bottom: 3px;
background: #ffffff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cycle_menu">
<p>Previous</p>
<p>Next</p>
</div>
<br>
<div class="hyperlinks">
<p class="current-url"></p>
</div>
<div class="menu">
<a class="nav-tab tab15" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab14" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab13" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab12" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab11" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab10" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab9" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab8" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab7" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab6" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab5" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab4" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab3" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab2" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
<a class="nav-tab tab1" href="http://www.dictionary.com" onclick="changecolor(this)">Menu item</a>
<br/>
<br/>
</div>
<iframe width="100%" frameborder="1"></iframe>
【问题讨论】:
-
我的回答是否有助于解决您的问题?如果是,请采纳。
标签: javascript jquery html css