1 回答
TA贡献1876条经验 获得超5个赞
所以看来我没有为复选框添加侦听器。这是最终的工作代码
var checkbox = document.getElementById('pricingSwitch')
var priceMonthly = document.getElementsByClassName("price-monthly")
var priceAnnual = document.getElementsByClassName("price-annual")
var durationMonth = document.getElementsByClassName("duration-month")
var durationYear = document.getElementsByClassName("duration-year")
function checker(checked) {
checked ? showAnnual() : showMonthly()
}
function showAnnual() {
priceMonthly[0].style.display = "none"
priceAnnual[0].style.display = "inline-block"
durationMonth[0].style.display = "none"
durationYear[0].style.display = "inline-block"
}
function showMonthly() {
priceMonthly[0].style.display = "inline-block"
priceAnnual[0].style.display = "none"
durationMonth[0].style.display = "inline-block"
durationYear[0].style.display = "none"
}
checker(this.checked)
checkbox.addEventListener('change', function () {
checker(this.checked)
})
添加回答
举报