【问题标题】:Hide/Show div via Radio Buttons通过单选按钮隐藏/显示 div
【发布时间】: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);"/>&nbsp;Cash/Debit
<input type="radio" id="payment_type" value="cheque" name="payment_type" onchange="showhideFinancing(this.value);"/>&nbsp;Cheque
<input type="radio" id="payment_type" value="visa" checked="checked" name="payment_type" onchange="showhideFinancing(this.value);"/>&nbsp;VISA
<input type="radio" id="payment_type" value="mc" name="payment_type" onchange="showhideFinancing(this.value);"/>&nbsp;Mastercard
<input type="radio" id="payment_type" value="financing" name="payment_type" onchange="showhideFinancing(this.value);"/>&nbsp;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 未定义--谢谢!

【问题讨论】:

标签: javascript html onchange


【解决方案1】:

我认为它可能会说“getElementById”未定义的唯一原因是,如果您在将示例放在这里时没有在原始代码中输入错字(区分大小写始终是让我知道)或者如果您以某种方式在页面的其他位置重新定义了文档。

【讨论】:

  • 谈论制作一座鼹鼠山的山......就是这样......谢谢男人的欢呼!
【解决方案2】:

嗯,您确定您的 ID 正确吗? 检查重复项。不看实际代码很难判断。

【讨论】:

    【解决方案3】:

    这里的一切似乎都很稳固。如果你得到一个 getElementById() 没有定义,那么它可能是一个错字或一些缺失的语法,比如不匹配的括号。你可以假设你的 html 现在是正确的,专注于定义函数的脚本标记或文件我很确定你的问题出在那儿。

    发布更多该代码以获得更多帮助。

    【讨论】:

      【解决方案4】:

      你那里的代码,一行一行,在 Safari 中为我工作。 getElementByID 就像 DOM 的根实现的一部分;如果未定义,我认为您的 Firefox 有问题。

      http://firefiter.com/temp.php

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-28
        • 2013-06-25
        • 1970-01-01
        • 2013-07-06
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多