#match_email
{
margin-left:48px;
overflow:auto;
display:none;
width:200px;
border:1px solid #aaa;
background:#fff;
max-height:100px;
line-height:20px;
}
#match_email div
{
text-decoration:none;
color:#000;
width:200px;
}
#match_email div:hover
{
background:#aaa;
}
input
{
height:20px;
width:200px;
}
<div> 邮箱:<input type="text" name="email" id="email" autocomplete="off" onkeyup="match_mail(this.value)"/> <div id="match_email"></div> </div>
<script>
//mailBoxs里存储用来匹配的串
var mailBoxs = "@163.com @126.com @129.com"
mailBoxs += " @qq.com @vip.qq.com @foxmail.com @live.cn @hotmail.com @sina.com @sina.cn @vip.sina.com";
var matchmail = document.getElementById("match_email");
var email = document.getElementById("email");
function match_mail(keyword)
{
matchmail.innerHTML = "";
matchmail.style.display = "none";
if (!keyword)
return;
if (!keyword.match(/^[\w\.\-]+@\w*[\.]?\w*/))
return;
keyword = keyword.match(/@\w*[\.]?\w*/);
var matchs = mailBoxs.match(new RegExp(keyword+"[^ ]* ","gm"));
if (matchs)
{
matchs = matchs.join("").replace(/ $/,"").split(" ");
matchmail.style.display = "block";
for (var i = 0; i < matchs.length; i++)
{
matchmail.innerHTML += '<div>'+matchs[i]+'</div>';
}
}
}
//点击除了匹配框之外的任何地方,匹配框消失
document.onclick = function(e)
{
var target = e.target;
if (target.id != "matchmail")
matchmail.style.display = "none";
}
//将匹配框上鼠标所点的字符放入输入框
matchmail.onclick = function(e)
{
var target = e.target;
email.value = email.value.replace(/@.*/,target.innerHTML);
}
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有