带过滤器引导程序的搜索栏

时间:2015-09-17 20:52:08

标签: html css html5 twitter-bootstrap navbar

我如何实施带过滤器的搜索栏,就像这里提到的那样:bootstrap amazon style search bar enter image description here

我在bootstraps page上看到的所有内容都指的是带有重定向的下拉列表,而不是选择列表:

这是我到目前为止所做的,但它看起来并不那么好,我不确定我是否正确地做到了。

enter image description here

<div class="col-md-9 col-md-push-1 ">
    <h3 class="text-center">Manage Users</h3>
    <div class="container">
        <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
                <div class="input-group">
                    <div class="input-group-btn search-panel">
                        <select class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <option>All</option>
                            <option>Username</option>
                            <option>Email</option>
                            <option>Student Code</option>
                        </select>
                    </div>

                    <input type="hidden" name="search_param" value="all" id="search_param">
                    <input type="text" class="form-control" name="x" placeholder="Search term...">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:3)

好吧,我相信您需要将输入包装在代码中缺少的form标记中。此外,select代码需要name属性,options必须设置value

下拉菜单应该按预期工作,不需要隐藏输入 - 只需解析select标记中的值。

HTML代码(忽略引导程序库链接) - JSFiddle

&#13;
&#13;
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<div class="col-md-9 col-md-push-1">
    <h3 class="text-center">Manage Users</h3>
    <div class="container">
        <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
                <form action="#" method="get" id="searchForm" class="input-group">
                    
                    <div class="input-group-btn search-panel">
                        <select name="search_param" id="search_param" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <option value="all">All</option>
                            <option value="username">Username</option>
                            <option value="email">Email</option>
                            <option value="studentcode">Student Code</option>
                        </select>
                    </div>
                    <input type="text" class="form-control" name="x" placeholder="Search term...">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="submit">
                           <span class="glyphicon glyphicon-search"></span>
                        </button>
                    </span>
                </form><!-- end form -->     
            </div><!-- end col-xs-8 -->       
        </div><!-- end row -->  
    </div><!-- end container -->    
</div><!-- end col-md-9 -->
&#13;
&#13;
&#13;

如果它不起作用那么它可能是一个javascript问题,每次你选择一个选项时刷新页面......