【发布时间】:2011-03-05 11:43:06
【问题描述】:
我正在尝试根据某些单选按钮的值隐藏或显示 div,css 默认 div 为 display='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 未定义--谢谢!
【问题讨论】:
-
创建的 jsFiddle:jsfiddle.net/r65f6 适合我!
标签: javascript html onchange