Ich habe eine Lösung auf GitHub gefunden: https://github.com/yuku-t/jquery-textcomplete (Danke yuku-t für das Schreiben dieses nette Plugin!).
Zuerst sind <script src="path/to/jquery.js"></script> <script src="path/to/jquery.textcomplete.js"></script>
Die html
<textarea class="form-control" id="textarea" rows="4" style="position: relative; outline: 0px; background: transparent;"></textarea>
Das Skript
$('textarea').textcomplete([{
id: 'words',
match: /(^|\b)(\w{2,})$/,
search: function (term, callback) {
var words = ['google', 'facebook', 'linkedin'];
callback($.map(words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
replace: function (word) {
return word + ' ';
}
},
{
id: 'names',
mentions: ['peter','steven', 'jeffrey', 'paul'],
match: /\[email protected](\w*)$/,
search: function (term, callback) {
callback($.map(this.mentions, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
index: 1,
replace: function (mention) {
return '@' + mention + ' ';
}
},
{
id: 'tasks',
tasks: ['invoice','call', 'email', 'put on hold'],
match: /\B#(\w*)$/,
search: function (term, callback) {
callback($.map(this.tasks, function (task) {
return task.indexOf(term) === 0 ? task : null;
}));
},
index: 1,
replace: function (task) {
return '#' + task + ' ';
}
}
]);
prüfen http://codepen.io/jmdejongh/pen/EyKQrZ
Nice one! Ich würde sagen müssen. Trotzdem solltest du hinzufügen, was immer du versucht hast. – Jai
Ich habe solche Lösungen schon einmal gesehen, und ich habe versucht, ein jquery-Plugin zu finden, das so etwas macht. Ich nehme an, dass es eine Standardlösung für ths gibt. – Jeffrey