我试图使用jquery-textcomplete。但它根本不起作用。检查以下代码,请帮助我:
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>
<style>
body {
background: #fff;
}
</style>
<script>
$('#textcomplete').textcomplete([{
words: ['anu', 'annamma', 'googlee', 'suresh namal', 'facebook', 'github', 'microsoft', 'yahoo', 'stackoverflow'],
match: /(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,
search: function (term, callback) {
console.log("inside search");
callback($.map(this.words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 2,
replace: function (word) {
return word + ' ';
}
}]);
</script>
</head>
<body>
<div>
<form>
<textarea id="textcomplete"></textarea>
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
效果很好!
由于正则表达式/(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/
,您应输入至少2个字符。
如果要输入1个字符,可以像这样更改正则表达式:
/(^|\S*)([^\u0000-\u007f]{1,}|\w{1,})$/