开源地址:https://github.com/yuezhongxin/Mention.js
插件效果:类似于微博或 github 中 @user 列表效果。
这是个二次开发的插件,花了几天时间,对 Mention.js(作者 jakiestfu) 进行了一些改进,主要是下面几个方面:
下面是四种配置和效果展示。
配置代码:
<body> <textarea id="full"></textarea> <link rel="stylesheet" type="text/CSS" href="../css/mention.css"> <script src="../scripts/jquery-1.10.2.js"></script> <script type='text/javascript' src="../scripts/mention-typeahead.js"></script> <script type='text/Javascript' src="../scripts/mention.js"></script> <script type='text/javascript' src="../scripts/textarea-caret-position.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#full").mention({ typeaheadOpts: { search: search } }); }); function search(key) { //在这里可以写后台查询代码 var data = [{ name: 'Rob Dyrdek', image: 'http://placekitten.com/25/24' }, { name: 'Rick Bahner', image: 'http://placekitten.com/25/23' }]; console.log("key:" + key); return data; } </script></body>
配置代码:
<body> <textarea id="full"></textarea> <link rel="stylesheet" type="text/css" href="../css/mention.css"> <script src="../scripts/jquery-1.10.2.js"></script> <script type='text/javascript' src="../scripts/mention-typeahead.js"></script> <script type='text/javascript' src="../scripts/mention.js"></script> <script type='text/javascript' src="../scripts/textarea-caret-position.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#full").mention({ typeaheadOpts: { search: search, under: true } }); }); function search(key) { //在这里可以写后台查询代码 var data = [{ name: 'Rob Dyrdek', image: 'http://placekitten.com/25/24' }, { name: 'Rick Bahner', image: 'http://placekitten.com/25/23' }]; console.log("key:" + key); return data; } </script></body>
配置代码:
<body> <textarea id="full"></textarea> <link rel="stylesheet" type="text/css" href="../css/mention-simple.css"> <script src="../scripts/jquery-1.10.2.js"></script> <script type='text/javascript' src="../scripts/mention-typeahead.js"></script> <script type='text/javascript' src="../scripts/mention.js"></script> <script type='text/javascript' src="../scripts/textarea-caret-position.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#full").mention({ typeaheadOpts: { search: search, under: true } }); }); function search(key) { //在这里可以写后台查询代码 var data = [{ name: 'Rob Dyrdek', image: 'http://placekitten.com/25/24' }, { name: 'Rick Bahner', image: 'http://placekitten.com/25/23' }]; console.log("key:" + key); return data; } </script></body>
配置代码:
<body> <textarea id="full"></textarea> <link rel="stylesheet" type="text/css" href="../css/mention-simple.css"> <script src="../scripts/jquery-1.10.2.js"></script> <script type='text/javascript' src="../scripts/mention-typeahead.js"></script> <script type='text/javascript' src="../scripts/mention.js"></script> <script type='text/javascript' src="../scripts/textarea-caret-position.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#full").mention({ typeaheadOpts: { search: search, under: true, fixed: true } }); }); function search(key) { //在这里可以写后台查询代码 var data = [{ name: 'Rob Dyrdek', image: 'http://placekitten.com/25/24' }, { name: 'Rick Bahner', image: 'http://placekitten.com/25/23' }]; console.log("key:" + key); return data; } </script></body>
新闻热点
疑难解答