开发者

jQuery hide/show with select tag

开发者 https://www.devze.com 2023-01-02 20:47 出处:网络
I\'ve been asked to create a hide/show function with a select tag. The function pretty much would be when you click on one of the options in the select tag it will open a div associate with the div of

I've been asked to create a hide/show function with a select tag. The function pretty much would be when you click on one of the options in the select tag it will open a div associate with the div of course. To be honest I have no idea how approach this function. Find below the html code.

<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://productiont开发者_如何学编程rade.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>


I took your code above and made a jsfiddle with (I believe) the functionality you were looking for.


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

Untested, but I think that'll work ... it's very rough, but a jumping off point, and can most definitely be done better.


Or better

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消