javascript - 选择器面板,Javascript

标签 javascript html css

    $('#select-page').bind('change', function(){
        alert('hi!');
    });

        <select id="select-page">
          <option value="hi">Page 1</option>
          <option value="hi2">Page 2</option>
           <!-- the amount of options in here varies all the time -->
        </select>

你好,

我正在尝试制作一个选项卡切换面板的功能,除了选项卡之外,我想使用一个选择下拉菜单在面板(divs)之间切换。

我怎样才能做到这一点? (我正在使用 jQuery 库)。

祝你有个美好的一天

最佳答案

你可以尝试这样的事情。

HTML

<select id="select-page">
    <option value="#hi">Page 1</option> <!--Set the options id of the div/panel to be displayed-->
    <option value="#hi2">Page 2</option>
    <option value="#hi3">Page 3</option>
    <option value="#hi4">Page 4</option>
    <!-- the amount of options in here varies -->
</select>
<div class="content" id="hi">Content1</div>
<div class="content" id="hi2">Content2</div>
<div class="content" id="hi3">Content3</div>
<div class="content" id="hi4">Content4</div>

JS

$(function(){
    $('.content').eq(0).show(); //show the first item as default
    $('#select-page').bind('change', function () {
        $('.content').slideUp(); //slide up everything.You can also use .hide() insetad of slideUp().
        $(this.value).slideDown(); //slide down the one respective to this option. You can also use .show() instead of slideDown()
    });
});

对于这种简单的布局,您可以使用链接并过滤出仅一个语句。

$('#select-page').bind('change', function () {
    $('.content').slideUp().filter(this.value).slideDown();
});

Demo

一些引用

slideDown , slideUp , show , hide , filter

关于javascript - 选择器面板,Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16866892/

相关文章:

javascript - Accordion 菜单 - 事件状态

jquery - 在 Jquery UI 选项卡上添加 flexslider(s) - 让它们工作

javascript - 在 Traccar 应用程序中更改或添加元素

javascript - 如何使用 JQuery 追加 ajax 成功响应后聚焦到 div

javascript - Fullcalendar Scheduler - 多用户 View 不工作

javascript - 可点击的 jquery 表格行

php - 如何使用 anchor 标记打开存储在 MySQL 表中的 PDF 文件

javascript - jQuery iframe-使用 iframe 时如何获取父窗口 URL?

html - 当宽度设置为 100% 时,如何让 Html Table 遵守边距?

css - 原始 CSS 文件中的条件 IE8 样式?