jQuery使用select标签隐藏/显示

时间:2010-06-10 18:13:35

标签: jquery html css

我被要求使用select标签创建隐藏/显示功能。这个函数几乎就是当你点击select标签中的一个选项时,它会打开div与div的关联。说实话,我不知道如何处理这个功能。在下面找到html代码。

<div class="adwizard">
                            <select id="selectdrop" name="selectdrop" class="adwizard-bullet">
                                    <option value="adwizard">AdWizard</option>
                                    <option value="collateral">Collateral Ordering Tool</option>
                                    <option value="ebrochure">eBrochures</option>
                                    <option value="brand">Brand Center</option>
                                    <option value="funtees">FunTees</option>
                            </select>
                    </div>

                     <div class="panels">   
                        <div id="adwizard" class="sub-box showhide">
                            <img src="../images/bookccl/img-adwizard.gif" width="95" height="24" alt="AdWizard" />
                            <p>Let Carnival help you grow your business with our great tools! Lor ipsum dolor sit amet. <a href="https://www.carnivaladwizard.com/home.asp">Learn More</a></p>
                        </div>

                         <div id="collateral" class="sub-box showhide">
                            <p>The Collateral Ordering Tool makes it easy for you to order destination brochures and the sales DVD for that upcoming event. <a href="http://carnival.litorders.com/workplace.asp">Learn More</a></p>
                        </div>

                        <div id="ebrochure" class="sub-box showhide">
                            <img src="../images/bookccl/img-ebrochure.gif" width="164" height="39" alt="Brochures" />
                            <p>Show your clients that you're listening to their specific vacation needs by delivering relevant planning info quickly.  <a href="http://productiontrade.carnivalbrochures.com/start.aspx">Learn More</a></p>
                        </div>

                         <div id="brand" class="sub-box showhide">
                            <p>Carnival Brand Center is where you'll find information on our strategy, guidlines, templates and artwork.   <a href="https://carnival.monigle2.net/user_info.asp?login_type=agent">Learn More</a></p>
                        </div>

                        <div id="funtees" class="sub-box showhide">
                            <img src="../images/bookccl/img-funtees.gif" width="164" height="39" alt="Funtees" />
                            <p>Create your very own Fun Design shirts to commemorate that special occasion aboard a Carnival "Fun Ship!"  <a href="http://carnival.victorydyo.com/">Learn More</a></p>
                        </div>
                    </div><!-- ends .panel -->
                    <a class="view" href="#">See All Marketing Tools</a>
                </div>

3 个答案:

答案 0 :(得分:2)

我上面的代码和made a jsfiddle带有(我相信)您正在寻找的功能。

答案 1 :(得分:1)

$(document).ready(function() {
    $('#selectdrop').change(function() {
        $('.panels div').hide();
        var panel = $(this).val();
        $('#' + panel).show();
    });
});

未经测试,但我认为它会起作用......它非常粗糙,但是跳跃点,并且绝对可以做得更好。

答案 2 :(得分:0)

或更好

<head>
<script>
$(document).ready(function() {
    $('.panels div').hide();// << IMPORTANT
    $('#selectdrop').change(function() {
        $('.panels div').slideUp();
        var panel = $(this).val();
        $('#' + panel).slideDown();
    });
});
</script>
</head>
<body>
.. The page ..
</body>