我创建了一个可直接点击的列表,但用户还应该能够使用向前和向后按钮在列表中循环。目前我列出的项目确实将颜色更改为红色。有没有一种方法可能使用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>
难道我的回答帮助解决问题了吗?如果是,请接受它。 –