jQuery实现输入邮箱地址自动提示
时间: 2023-11-28 14:47:21 浏览: 35
可以使用jQuery UI中的Autocomplete插件来实现输入邮箱地址自动提示。
以下是一个简单的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Input email autocomplete</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
$(function() {
var availableEmails = [
"example@gmail.com",
"example@yahoo.com",
"example@hotmail.com",
"example@outlook.com",
"example@aol.com",
"example@icloud.com"
];
$("#email").autocomplete({
source: availableEmails
});
});
</script>
</head>
<body>
<label for="email">Email:</label>
<input id="email" type="text">
</body>
</html>
```
在上述代码中,我们首先引入了jQuery和jQuery UI库,然后定义了一个可用的邮箱地址列表,最后使用Autocomplete插件将其绑定到输入框上。当用户在输入框中输入文本时,Autocomplete插件将自动显示匹配的邮箱地址,用户可以选择其中之一或继续输入。