文本框输入邮箱自动联想补全
程序员文章站
2022-06-01 12:46:07
...
转载:https://www.cnblogs.com/xionggeclub/p/5880938.html?utm_source=itdadao&utm_medium=referral
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title></title>
</head>
<body>
<input type="text" list="input_list" name="text" placeholder="请输入邮箱"/>
<datalist id="input_list"></datalist>
</body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
function inputList(input,list){
var mailBox = [
"@qq.com",
"@sina.com",
"@163.com",
"@126.com",
"@yahoo.com.cn",
"@gmail.com",
"@sohu.com"
];
input.bind('input propertychange', function() {
var key = input.val();
if(key.indexOf("@") != -1){
key = key.slice(0,key.indexOf("@"));
}
var mailBoxLen = mailBox.length;
var html = "";
for(var i=0; i<mailBoxLen; i++){
html += '<option value="'+ key + mailBox[i] +'"></option>';
}
list.html(html);
});
}
inputList($("input"),$("#input_list"));
</script>
</html>
上一篇: 性能调优之 Weblogic 调优