显示/隐藏在IE8中不起作用 - JQUERY

时间:2014-02-19 09:38:24

标签: jquery internet-explorer-8

我曾尝试过与我类似的其他问题,但没有一个能帮助我。

我有一些多个div,当用户点击输入时,我需要逐个显示和隐藏它们。我的代码在除IE8之外的所有浏览器中运行良好,其中没有任何事情发生,否则div不显示。 有人可以帮我解决这个问题吗?

这是我的HTML

<div id="tabbedBox">
                    <form action="" method="">
                        <div class="tabbed" id="selectMe">
                            <input type="radio" target="1" id="pvl" name="radios" value="a" checked>
                            <label class="pvl"  for="pvl">PVL</label>
                            <input type="radio" target="2" id="cvl" name="radios" value="b">
                            <label class="cvl" for="cvl">CVL</label>
                            <input type="radio" target="3" id="industrial" name="radios" value="c">
                            <label class="industrial" for="industrial">Industrial</label>
                            <input type="radio" target="4" id="distributor" name="radios" value="d">
                            <label class="distributor" for="distributor">Distributor</label>
                        </div>





                        <div class="pvlBox tabbedContent" id="div1">
                            <div class="select">
                                <input type="radio" id="installed" name="radios" value="" checked>
                                <label for="installed">Installed</label>
                            </div>
                            <span>Installed</span>
                            <div class="select">
                                <input type="radio" id="retail" name="radios" value="">
                                <label for="retail">Retail</label>
                            </div>
                            <span>Retail</span>
                            <div class="select">
                                <input type="radio" id="service" name="radios" value="">
                                <label for="service">Service Station</label>
                            </div>
                            <span>Service Station</span>
                        </div>

                            <div class="cvlBox tabbedContent" id="div2" style="display:none">
                                CVL CONTENT
                            <div class="select">
                                <input type="radio" id="installed" name="radios" value="" checked>
                                <label for="installed">Installed</label>
                            </div>
                            <span>Installed</span>
                            <div class="select">
                                <input type="radio" id="retail" name="radios" value="">
                                <label for="retail">Retail</label>
                            </div>
                            <span>Retail</span>
                            <div class="select">
                                <input type="radio" id="service" name="radios" value="">
                                <label for="service">Service Station</label>
                            </div>
                            <span>Service Station</span>
                        </div>
                            <div class="industrialBox tabbedContent" id="div3"  style="display:none">
                                INDUSTRIAL CONTENT
                            <div class="select">
                                <input type="radio" id="installed" name="radios" value="" checked>
                                <label for="installed">Installed</label>
                            </div>
                            <span>Installed</span>
                            <div class="select">
                                <input type="radio" id="retail" name="radios" value="">
                                <label for="retail">Retail</label>
                            </div>
                            <span>Retail</span>
                            <div class="select">
                                <input type="radio" id="service" name="radios" value="">
                                <label for="service">Service Station</label>
                            </div>
                            <span>Service Station</span>
                        </div>

                            <div class="distributorBox tabbedContent" id="div4"  style="display:none">
                                DISTRIBUTOR CONTENT
                            <div class="select">
                                <input type="radio" id="installed" name="radios" value="" checked>
                                <label for="installed">Installed</label>
                            </div>
                            <span>Installed</span>
                            <div class="select">
                                <input type="radio" id="retail" name="radios" value="">
                                <label for="retail">Retail</label>
                            </div>
                            <span>Retail</span>
                            <div class="select">
                                <input type="radio" id="service" name="radios" value="">
                                <label for="service">Service Station</label>
                            </div>
                            <span>Service Station</span>
                        </div>

                        <br/>


                    </form>
            </div><!--/end tabbedbox-->

这是jquery代码:

$('#pvl').click(function() {
        $('div[id^=div]').hide();
        $('#div1').show();

    });
    $('#cvl').click(function() {
        $('div[id^=div]').hide();
        $('#div2').show();
    });

    $('#industrial').click(function() {
        $('div[id^=div]').hide();
        $('#div3').show();
    });

    $('#distributor').click(function() {
        $('div[id^=div]').hide();
        $('#div4').show();
    });

});

1 个答案:

答案 0 :(得分:0)

我添加了一些标记来简化脚本。还将click事件更改为change-event:

Fiddle

脚本:

$(function () {
    $(".js-change").on("change", function () {
        $(".Box").hide();
        $("." + $(this).data("show-content")).show();
    });
});

Html(将类和数据属性添加到radiobuttons):

<div id="tabbedBox">
    <form action="" method="">
        <div class="tabbed" id="selectMe">
            <input type="radio" target="1" id="pvl" name="radios" value="a" 
                  class="js-change" data-show-content="pvlBox" checked>
            <label class="pvl" for="pvl">PVL</label>
            <input type="radio" target="2" id="cvl" name="radios" value="b" 
                  class="js-change" data-show-content="cvlBox">
            <label class="cvl" for="cvl">CVL</label>
            <input type="radio" target="3" id="industrial" name="radios" value="c"
                  class="js-change" data-show-content="industrialBox">
            <label class="industrial" for="industrial">Industrial</label>
            <input type="radio" target="4" id="distributor" name="radios" value="d"
                  class="js-change" data-show-content="distributorBox">
            <label class="distributor" for="distributor">Distributor</label>
        </div>
        <div class="Box pvlBox tabbedContent">
            <div class="select">
                <input type="radio" id="installed" name="radios" value="" checked>
                <label for="installed">Installed</label>
            </div> <span>Installed</span>

            <div class="select">
                <input type="radio" id="retail" name="radios" value="">
                <label for="retail">Retail</label>
            </div> <span>Retail</span>

            <div class="select">
                <input type="radio" id="service" name="radios" value="">
                <label for="service">Service Station</label>
            </div> <span>Service Station</span>

        </div>
        <div class="Box cvlBox tabbedContent" style="display:none">CVL CONTENT
            <div class="select">
                <input type="radio" id="installed" name="radios" value="" checked>
                <label for="installed">Installed</label>
            </div> <span>Installed</span>

            <div class="select">
                <input type="radio" id="retail" name="radios" value="">
                <label for="retail">Retail</label>
            </div> <span>Retail</span>

            <div class="select">
                <input type="radio" id="service" name="radios" value="">
                <label for="service">Service Station</label>
            </div> <span>Service Station</span>

        </div>
        <div class="Box industrialBox tabbedContent" style="display:none">INDUSTRIAL CONTENT
            <div class="select">
                <input type="radio" id="installed" name="radios" value="" checked>
                <label for="installed">Installed</label>
            </div> <span>Installed</span>

            <div class="select">
                <input type="radio" id="retail" name="radios" value="">
                <label for="retail">Retail</label>
            </div> <span>Retail</span>

            <div class="select">
                <input type="radio" id="service" name="radios" value="">
                <label for="service">Service Station</label>
            </div> <span>Service Station</span>

        </div>
        <div class="Box distributorBox tabbedContent" id="div4" style="display:none">DISTRIBUTOR CONTENT
            <div class="select">
                <input type="radio" id="installed" name="radios" value="" checked>
                <label for="installed">Installed</label>
            </div> <span>Installed</span>

            <div class="select">
                <input type="radio" id="retail" name="radios" value="">
                <label for="retail">Retail</label>
            </div> <span>Retail</span>

            <div class="select">
                <input type="radio" id="service" name="radios" value="">
                <label for="service">Service Station</label>
            </div> <span>Service Station</span>

        </div>
        <br/>
    </form>
</div>
<!--/end tabbedbox-->