我有一个登录表单,询问电子邮件ID和密码。在电子邮件ID字段中,我要在输入xxx @时将自动建议实施为@gmail.com
。谁能告诉我如何实施?我正在使用下面给出的代码
$(function () {
var acList = ['gmail.com',
'yahoo.com',
'hotmail.com'
];
var lastDot = -1;
$("#tags").autocomplete({
minLength: 0,
source: function (request, response) {
if (lastDot>=0) {
response($.ui.autocomplete.filter(
acList, extractLast(request.term.substring(lastDot+1))));
}
},
focus: function () {
return false;
},
select: function (event, ui) {
var terms = split(this.value);
terms.pop();
terms.push(ui.item.value);
terms.push("");
this.value = this.value.substr(0,lastDot+1);
this.value += terms.join("");
return false;
}
}).on("keypress", function (e) {
var keys = [];
keys.unshift(e.which);
if (String.fromCharCode(keys[0]) == "@") {
lastDot = $("#tags").val().length;
}
});
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
});
<input id="tags" type="input" />
答案 0 :(得分:0)
将此添加到您的脑海:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
您忘记加载脚本中使用的jQuery库。
致谢。