1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
所以看來(lái)我沒(méi)有為復(fù)選框添加偵聽(tīng)器。這是最終的工作代碼
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)
})
添加回答
舉報(bào)