開源地址:https://github.com/yuezhongxin/Mention.jsjavascript
插件效果:相似於微博或 github 中 @user 列表效果。css
這是個二次開發的插件,花了幾天時間,對 Mention.js(做者 jakiestfu) 進行了一些改進,主要是下面幾個方面:html
下面是四種配置和效果展現。java
配置代碼:jquery
<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>
配置代碼:git
<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>
配置代碼:github
<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>
配置代碼:bootstrap
<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>