我试图根据某些单选按钮的值隐藏或显示 div,css 默认 div 显示='none'
这里是输入
<input type="radio" id="payment_type" value="cash" checked="checked" name="payment_type" onchange="showhideFinancing(this.value);"/> Cash/Debit
<input type="radio" id="payment_type" value="cheque" name="payment_type" onchange="showhideFinancing(this.value);"/> Cheque
<input type="radio" id="payment_type" value="visa" checked="checked" name="payment_type" onchange="showhideFinancing(this.value);"/> VISA
<input type="radio" id="payment_type" value="mc" name="payment_type" onchange="showhideFinancing(this.value);"/> Mastercard
<input type="radio" id="payment_type" value="financing" name="payment_type" onchange="showhideFinancing(this.value);"/> Financing
这是 div:
<div id="financing">
...
</div>
我的 Javascript fn 看起来像这样:
function showhideFinancing(payment_type) {
if (payment_type == "financing") {
document.getElementById("financing").style.display = 'block';
} else {
document.getElementById("financing").style.display = 'none';
}
}
Firebug 显示 getElementById 未定义 - 谢谢!
最佳答案
我认为它可能会说“getElementById”未定义的唯一原因是,如果您在原始代码中犯了一个拼写错误,但在将示例放在这里时却没有这样做(区分大小写始终是明白我的意思)或者如果您以某种方式在页面的其他位置重新定义了文档。
关于javascript - 通过单选按钮隐藏/显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3070780/