【发布时间】:2016-04-15 15:27:04
【问题描述】:
我在下面编写了切换代码,我需要在“地图/视图”切换时切换“活动”类。当我首先单击另一个链接时,应删除并应用于单击的链接。
HTML:
<div class="member-view-switch">
<a href="#" class="toggle-button active">Tile</a>
<a href="#" class="toggle-button">Map</a>
</div>
<div class="toggle-item target-tile-view">
Tile View
</div>
<div class="toggle-item target-map-view">
Map View
</div>
CSS:
.member-view-switch {
margin-bottom: 20px;
}
a,
:hover,
:focus {
color;
#333333;
text-decoration: none;
padding-right: 15px;
}
.active {
color: blue;
font-weight: bold;
}
.toggle-item {
border: 1px solid #333;
padding: 20px;
margin-bottom: 20px;
}
jQuery:
$(document).ready(function() {
$(".target-map-view").css("display", "none");
$(".toggle-button").click(function() {
if ($(this).hasClass("active")) {
$(".target-tile-view").show();
$(".target-map-view").hide();
} else {
$(".target-tile-view").hide();
$(".target-map-view").show();
}
});
});
【问题讨论】:
标签: jquery