我一直在尝试使用bootstrap在select表单中添加搜索功能。这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="http://getbootstrap.com/favicon.ico">
<title>Depots list</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Latest compiled and minified bootstrap-select CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://getbootstrap.com/examples/starter-template/starter-template.css" rel="stylesheet">
<link href="./css/st.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="http://getbootstrap.com/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="box">
<!-- /.box-header -->
<div class="box-body">
<form>
<div class="form-group row">
<label for="" class="col-sm-2 form-control-label">Country</label>
<div class="col-sm-10">
<select class="form-control selectpicker" id="select-country" placeholder="" data-live-search="true">
<options>China</options>
<options>Malaysia</options>
<options>Singapore</options>
</select>
</div>
</div>
</form>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container -->
字符串
select表单中的form-control和selectpicker两个类矛盾。我的代码只对form-control类有效。
对于选择搜索,我使用了以下方法:https://developer.snapappointments.com/bootstrap-select/examples/#live-search
我的问题是:如何在select标签中同时使用form-control和selectpicker类?我已经用正常的程序写了一个空格的类名。但似乎不起作用。
6条答案
按热度按时间uplii1fm1#
要获得搜索功能,必须为每个选项设置
data-tokens
属性。这是添加后的代码。如果你需要额外的帮助,请告诉我。个字符
jc3wubiy2#
多项选择表格和可搜索
个字符
kqlmhetl3#
字符串
zed5wv104#
字符串
我认为
data-token=
不是强制属性。我在Asp.net Core中使用了Select Option中的Search Box。
tuwxkamq5#
如果您使用的是bootstrap selectpicker,只需在select标记中添加一个HTML属性,并在脚本中对其进行初始化。
data-live-search=“true”
字符串
zz2j4svz6#
我用过这个非常简单的JS,它能创造奇迹
字符串
使用https://silviomoreto.github.io/bootstrap-select/