【发布时间】:2014-06-11 10:45:43
【问题描述】:
所以我在 haml 中有这个简单的菜单,它是用来标记的
.monthly_tab#selected
Monthly
.yearly_tab#notselected
Yearly
这是在标签之间切换的 JQuery 代码。它不能完全正确地工作。我可以从 .monthly_tab 切换到 .yearly_tab,但不能切换回来。
$(document).ready(function() {
$("#notselected").click(function(){
if ($("#notselected").hasClass("yearly_tab")){
$(".yearly_tab#notselected").removeAttr("id")
$(".yearly_tab").attr("id", "selected")
$(".monthly_tab#selected").removeAttr("id")
$(".monthly_tab").attr("id", "notselected")
$(".prices.monthly").hide()
$(".prices.yearly").show()
}else if ($("#notselected").hasClass("monthly_tab")){
$(".monthly_tab#notselected").removeAttr("id")
$(".monthly_tab").attr("id", "selected")
$(".yearly_tab#selected").removeAttr("id")
$(".yearly_tab").attr("id", "notselected")
$(".prices.yearly").hide()
$(".prices.monthly").show()
}
});
});
【问题讨论】: