代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--360浏览器优先以webkit内核解析-->
<title>H+ 后台主题UI框架 - 搜索建议</title>
<link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="css/animate.min.css" rel="stylesheet">
<link href="css/style.min.css?v=4.0.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
<div class="row">
<div class="col-sm-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>combox 搜索建议插件</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="buttons.html#">选项1</a>
</li>
<li><a href="buttons.html#">选项2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<p>这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件.</p>
<p>使用说明:<a href="https://github.com/lzwme/bootstrap-suggest-plugin" target="_blank">https://github.com/lzwme/bootstrap-suggest-plugin</a>
</p>
<form action="index_submit" method="get" accept-charset="utf-8" role="form">
<hr>
<h3>测试(URL 获取)</h3>
<p>配置了 data-id,非下拉菜单选择输入则背景色警告。</p>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" id="test">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
<!-- /btn-group -->
</div>
</div>
</div>
<hr>
<h3>测试(URL 获取)</h3>
<p>不展示下拉菜单按钮。</p>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" id="testNoBtn">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
<!-- /btn-group -->
</div>
</div>
</div>
<hr>
<h3>测试(json 数据中获取)</h3>
<p>默认启用空关键字检索。</p>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" id="test_data">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
<!-- /btn-group -->
</div>
</div>
</div>
<hr>
<h3>百度搜索</h3>
<p>支持逗号分隔多关键字</p>
<div class="row">
<div class="col-lg-6">
<div class="input-group" style="width: 300px;">
<input type="text" class="form-control" id="baidu">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
<!-- /btn-group -->
</div>
</div>
</div>
<hr>
<h3>淘宝搜索</h3>
<p>支持逗号分隔多关键字</p>
<div class="row">
<div class="col-lg-6">
<div class="input-group" style="width: 400px;">
<input type="text" class="form-control" id="taobao">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
<!-- /btn-group -->
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>使用说明</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="buttons.html#">选项1</a>
</li>
<li><a href="buttons.html#">选项2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
<h1><a id="user-content-bootstrap-search-suggest" class="anchor" href="#bootstrap-search-suggest" aria-hidden="true"><span class="octicon octicon-link"></span></a>Bootstrap Search Suggest</h1>
<p>这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件,必须使用于按钮式下拉菜单组件上。</p>
<h2>功能说明</h2>
<ul>
<li>搜索方式:从 data.value 的有效字段数据中查询 keyword 的出现,或字段数据包含于 keyword 中</li>
<li>支持单关键字、多关键字的输入搜索建议,多关键字可自定义分隔符</li>
<li>支持按 data 数组数据搜索、按 URL 请求搜索和按首次请求URL数据并缓存搜索三种方式【getDataMethod】</li>
<li>单关键字会设置 data-id 和输入框内容两个值,以 indexId/idField 和 indexKey/idFiled 取值 data 的数据为准;多关键字只设置输入框值</li>
</ul>
<h2>快速上手</h2>
<ol>
<li>引入 jQuery、bootstrap.min.css、bootstrap.min.js</li>
<li>引入插件js: <code>bootstrap-suggest.min.js</code>
</li>
<li>初始化插件</li>
</ol>
<pre>var bsSuggest = $("input#test").bsSuggest({
url: "/rest/sys/getuserlist?keyword="
})</pre>
<p>具体使用请参考参数配置说明及demo 示例页面源码(<a href="http://lzw.me/pages/demo/bootstrap-suggest-plugin">Demo</a>)</p>
<h4>方法调用</h4>
<ol>
<li>禁用提示: <code>$("input#test").bsSuggest("disable");</code>
</li>
<li>启用提示: <code>$("input#test").bsSuggest("enable");</code>
</li>
<li>销毁插件: <code>$("input#test").bsSuggest("destroy");</code>
</li>
</ol>
<h4><a class="anchor"><span class="octicon octicon-link"></span></a>事件监听</h4>
<p>dataRequestSuccess: 当 AJAX 请求数据成功时触发,并传回结果到第二个参数</p>
<pre>$("input#test").on("dataRequestSuccess", function (event, result) {
console.log(result);
});</pre>
<p>onSetSelectValue:当从下拉菜单选取值时触发,并传回设置的数据到第二个参数 onUnsetSelectValue:当设置了 idField,且自由输入内容时触发(与背景警告色显示同步)</p>
<h2>配置参数</h2>
<p>参数列表中的值均为插件默认值</p>
<pre>{
url: null, //请求数据的 URL 地址
jsonp: null, //设置此参数名,将开启jsonp功能,否则使用json数据结构
data: {}, //提示所用的数据
getDataMethod: "firstByUrl", //获取数据的方式,url:一直从url请求;data:从 options.data 获取;firstByUrl:第一次从Url获取全部数据,之后从options.data获取
indexId: 0, //每组数据的第几个数据,作为input输入框的 data-id,设为 -1 且 idField 为空则不设置此值
indexKey: 0, //每组数据的第几个数据,作为input输入框的内容
idField: "", //每组数据的哪个字段作为 data-id,优先级高于 indexId 设置(推荐)
keyField: "", //每组数据的哪个字段作为输入框内容,优先级高于 indexKey 设置(推荐)
effectiveFields: [], //有效显示于列表中的字段,非有效字段都会过滤,默认全部,对自定义getData方法无效
effectiveFieldsAlias: {}, //有效字段的别名对象,用于 header 的显示
searchFields: [], //有效搜索字段,从前端搜索过滤数据时使用。effectiveFields 配置字段也会用于搜索过滤
showHeader: false, //是否显示选择列表的 header,默认有效字段大于一列时显示,否则不显示
showBtn: true, //是否显示下拉按钮
allowNoKeyword: true, //是否允许无关键字时请求数据
multiWord: false, //以分隔符号分割的多关键字支持
separator: ",", //多关键字支持时的分隔符,默认为半角逗号
processData: processData, //格式化数据的方法,返回数据格式参考 data 参数
getData: getData, //获取数据的方法
autoMinWidth: false, //是否自动最小宽度,设为 false 则最小宽度不小于输入框宽度
listAlign: "left", //提示列表对齐位置,left/right/auto
inputWarnColor: "rgba(255,0,0,.1)", //输入框内容不是下拉列表选择时的警告色
listStyle: {
"padding-top":0, "max-height": "375px", "max-width": "800px",
"overflow": "auto", "width": "auto",
"transition": "0.5s", "-webkit-transition": "0.5s", "-moz-transition": "0.5s", "-o-transition": "0.5s"
}, //列表的样式控制
listHoverStyle: 'background: #07d; color:#fff', //提示框列表鼠标悬浮的样式
listHoverCSS: "jhover", //提示框列表鼠标悬浮的样式名称
keyLeft: 37, //向左方向键
keyUp: 38, //向上方向键
keyRight: 39, //向右方向键
keyDown: 40, //向下方向键
keyEnter: 13 //回车键
}</pre>
<h2>使用示例</h2>
<p>请参考 index.html 文件源代码,提供了自定义数据、URL 请求数据、百度搜索API、淘宝搜索API的接口演示。</p>
<h2>二次开发</h2>
<ol>
<li><code>npm install grunt-cli -g</code>
</li>
<li><code>npm install</code>
</li>
<li><code>grunt watch</code>
</li>
</ol>
<h2><a id="user-content-note-on-patches--pull-requests" class="anchor" href="#note-on-patches--pull-requests" aria-hidden="true"><span class="octicon octicon-link"></span></a>Note on Patches / Pull Requests</h2>
<ul>
<li>Fork the project.</li>
<li>Make your feature addition or bug fix.</li>
<li>Send me a pull request. Bonus points for topic branches.</li>
</ul>
<h2><a id="user-content-设计制作" class="anchor" href="#设计制作" aria-hidden="true"><span class="octicon octicon-link"></span></a>设计制作</h2>
<p>该插件由<a href="http://lzw.me" target="_blank">志文工作室</a>开发和维护.</p>
</article>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.5"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script type="text/javascript">
var testBsSuggest=$("#test").bsSuggest({url:"js/plugins/suggest/data.json",idField:"userId",keyField:"userName"}).on("onDataRequestSuccess",function(e,result){console.log("onDataRequestSuccess: ",result)}).on("onSetSelectValue",function(e,keyword){console.log("onSetSelectValue: ",keyword)}).on("onUnsetSelectValue",function(e){console.log("onUnsetSelectValue")});var testBsSuggest=$("#testNoBtn").bsSuggest({url:"js/plugins/suggest/data.json",showBtn:false,idField:"userId",keyField:"userName"}).on("onDataRequestSuccess",function(e,result){console.log("onDataRequestSuccess: ",result)}).on("onSetSelectValue",function(e,keyword){console.log("onSetSelectValue: ",keyword)}).on("onUnsetSelectValue",function(e){console.log("onUnsetSelectValue")});var testdataBsSuggest=$("#test_data").bsSuggest({indexId:2,indexKey:1,data:{"value":[{"id":"0","word":"lzw","description":"http://lzw.me"},{"id":"1","word":"lzwme","description":"http://w.lzw.me"},{"id":"2","word":"meizu","description":"http://www.meizu.com"},{"id":"3","word":"flyme","description":"http://flyme.meizu.com"}],"defaults":"http://lzw.me"}});var baiduBsSuggest=$("#baidu").bsSuggest({allowNoKeyword:false,multiWord:true,separator:",",getDataMethod:"url",url:"http://unionsug.baidu.com/su?p=3&t="+(new Date()).getTime()+"&wd=",jsonp:"cb",processData:function(json){var i,len,data={value:[]};if(!json||!json.s||json.s.length===0){return false}console.log(json);len=json.s.length;jsonStr="{'value':[";for(i=0;i<len;i++){data.value.push({word:json.s[i]})}data.defaults="baidu";return data}});var taobaoBsSuggest=$("#taobao").bsSuggest({indexId:2,indexKey:1,allowNoKeyword:false,multiWord:true,separator:",",getDataMethod:"url",effectiveFieldsAlias:{Id:"序号",Keyword:"关键字",Count:"数量"},showHeader:true,url:"http://suggest.taobao.com/sug?code=utf-8&extras=1&q=",jsonp:"callback",processData:function(json){var i,len,data={value:[]};if(!json||!json.result||json.result.length==0){return false}console.log(json);len=json.result.length;for(i=0;i<len;i++){data.value.push({"Id":(i+1),"Keyword":json.result[i][0],"Count":json.result[i][1]})}console.log(data);return data}});$("form").submit(function(e){return false});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。