<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>输入Email相关字符自动提示Email地址</title>
<script src="js/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
body
{
margin:0px;
padding:0px;
font-family:Arial;
font-size:12px;
padding:10px;
}
#myemail, .newemail, .newemailtitle{
cursor:default;
line-height:18px;
}
</style>
</head>
<body>
Email <input id="me" type="text" value="" style="width:150px; height:18px; line-height:18px; border:1px solid #999;">
<script type="text/javascript">
var nowid;
var totalid;
var can1press = false;
var emailafter;
var emailbefor;
$(document).ready(function(){
$("#me").focus(function(){ //文本框获得焦点,插入Email提示层
$("#myemail").remove();
$(this).after("<div id='myemail' style='width:170px; height:auto; background:#fff; color:#6B6B6B; position:absolute; left:"+$(this).get(0).offsetLeft+"px; top:"+($(this).get(0).offsetTop+$(this).height()+2)+"px; border:1px solid #ccc;z-index:5px; '></div>");
if($("#myemail").html()){
$("#myemail").css("display","block");
$(".newemail").css("width",$("#myemail").width());
can1press = true;
} else {
$("#myemail").css("display","none");
can1press = false;
}
}).keyup(function(){ //文本框输入文字时,显示Email提示层和常用Email
var press = $("#me").val();
if (press!="" || press!=null){
var emailtxt = "";
var emailvar = new Array("@163.com","@126.com","@yahoo.com","@qq.com","@sina.com","@gmail.com","@hotmail.com","@foxmail.com");
totalid = emailvar.length;
var emailmy = "<div class='newemail' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + press + "</font></div>";
if(!(isEmail(press))){
for(var i=0; i<emailvar.length; i++) {
emailtxt = emailtxt + "<div class='newemail' onclick='getT("+ i +")' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + press + "</font>" + emailvar[i] + "</div>"
}
} else {
emailbefor = press.split("@")[0];
emailafter = "@" + press.split("@")[1];
for(var i=0; i<emailvar.length; i++) {
var theemail = emailvar[i];
if(theemail.indexOf(emailafter) == 0)
{
emailtxt = emailtxt + "<div class='newemail' onclick='getT("+ i +")' style='width:170px; color:#6B6B6B; overflow:hidden;'><font color='#D33022'>" + emailbefor + "</font>" + emailvar[i] + "</div>"
}
}
}
$("#myemail").html(emailmy+emailtxt);
if($("#myemail").html()){
$("#myemail").css("display","block");
$(".newemail").css("width",$("#myemail").width());
can1press = true;
} else {
$("#myemail").css("display","none");
can1press = false;
}
beforepress = press;
}
if (press=="" || press==null){
$("#myemail").html("");
$("#myemail").css("display","none");
}
})
$(document).click(function(){ //文本框失焦时删除层
if(can1press){
$("#myemail").remove();
can1press = false;
if($("#me").focus()){
can1press = false;
}
}
})
$(".newemail").on("mouseover",function(){ //鼠标经过提示Email时,高亮该条Email
$(".newemail").css("background","#FFF");
$(this).css("background","#CACACA");
$(this).focus();
nowid = $(this).index();
}).on("click",function(){ //鼠标点击Email时,文本框内容替换成该条Email,并删除提示层
var newhtml = $(this).html();
newhtml = newhtml.replace(/<.*?>/g,"");
$("#me").val(newhtml);
$("#myemail").remove();
})
$(document).bind("keydown",function(e)
{
if(can1press){
switch(e.which)
{
case 38:
if (nowid > 0){
$(".newemail").css("background","#FFF");
$(".newemail").eq(nowid).prev().css("background","#CACACA").focus();
nowid = nowid-1;
}
if(!nowid){
nowid = 0;
$(".newemail").css("background","#FFF");
$(".newemail").eq(nowid).css("background","#CACACA");
$(".newemail").eq(nowid).focus();
}
break;
case 40:
if (nowid < totalid){
$(".newemail").css("background","#FFF");
$(".newemail").eq(nowid).next().css("background","#CACACA").focus();
nowid = nowid+1;
}
if(!nowid){
nowid = 0;
$(".newemail").css("background","#FFF");
$(".newemail").eq(nowid).css("background","#CACACA");
$(".newemail").eq(nowid).focus();
}
break;
case 13:
var newhtml = $(".newemail").eq(nowid).html();
newhtml = newhtml.replace(/<.*?>/g,"");
$("#me").val(newhtml);
$("#myemail").remove();
}
}
})
})
//检查email邮箱
function isEmail(str){
if(str.indexOf("@") > 0)
{
return true;
} else {
return false;
}
}
function getT(obj) {
console.log(855);
console.log(obj);
}
</script>
在输入框中输入“qq”、“Sina”等等可以看到效果
</body>
</html>

仿造email后缀自动添加功能(1)的更多相关文章

  1. 仿造email后缀搜索功能(2)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 在Word中为标题样式添加自动编号功能

    原文地址:http://blog.chinaunix.net/uid-16685753-id-2738270.html 摘要: 本文可以帮助你在Office 2007中为Word标题样式添加和设置自动 ...

  3. MyEclipse添加ibatis DTD文件实现xml的自动提示功能

    当我们写ibatis配置文件的时候,希望有xml自动提示功能.这就需要我们添加DTD文件 SqlMapConfig.xml中开头部分有这么一句话 <!DOCTYPE sqlMapConfig P ...

  4. Laravel添加代码自动提示功能

    在使用Laravel框架的时候,可能会碰上代码无法自动提示的情况,那么如何添加自动提示功能呢? 1,首先在composer.json中加入以下内容: "require": { &q ...

  5. 在 jupyter 中添加菜单和自动完成功能

    在 jupyter 中添加菜单和自动完成功能 参考文档http://www.360doc.com/content/17/1103/14/1489589_700569828.shtmlhttp://to ...

  6. 去除partner页面消息 自动添加关注者的功能

    某些公司希望在partner页面说些partner的坏话,可是odoo居然自动添加了partner关注,这就尴尬了.... 如果恰搭建了邮件服务器,很有可能就自动发到了客户邮箱里,等着炸锅吧.... ...

  7. zabbix server的Discover功能,实现zabbix agent 大批量的自动添加,并链接到指定的模版(3)

    一.需求 zabbix 服务器可以手动加入zabbix-agent客户端,对于少量的机器,这没有什么.但到了线上,我们有大量的服务器需要监控时,如果再一个个的手动加的话,工作量势必会增加很多.这时,z ...

  8. WebStorm 编辑器 关闭自动保存功能及添加*星星标记

    WebStorm 关闭自动保存功能添加*星星标记为什么要关闭自动保存?      ​ 在前端项目工作当中,往往会采用自动化环境(Gulp.webpack等)当文本发生变化的时候就会自动编译代码.在we ...

  9. 用汇编语言给XP记事本添加“自动保存”功能 good

    [文章标题]: 用汇编语言给XP记事本添加“自动保存”功能 [文章作者]: newjueqi [作者邮箱]:zengjiansheng1@126.com [作者QQ]:190678908 [使用工具] ...

随机推荐

  1. 文笔很差系列4 - Kris Kremo

    转载请标注原链接 https://www.cnblogs.com/xczyd/p/11127671.html Kris Kremo老先生(1951年出生,1970年第一次正式登台,截止2019年练习时 ...

  2. CSS中 Padding和Margin两个属性的详细介绍和举例说明

    代码示例: <!doctype html> <html lang="en"> <head> <meta charset="UTF ...

  3. 实用的60个CSS代码片段[上]

    1.垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,可以很优雅的解决这个困惑: .verticalcenter{ position: re ...

  4. Volley源码分析

    取消请求的源码分析: public void cancelAll(RequestFilter filter) { synchronized (mCurrentRequests) { for (Requ ...

  5. ORA-02291: 违反完整约束条件 - 未找到父项关键字问题解决

    ORA-02291: 违反完整约束条件 - 未找到父项关键字问题解决 总体说说可能出现的原因: 情况场景: 表A中有个字段是外键,关联了表B中的某字段,再往表A插入数据时,会出现这种情况. 可能原因: ...

  6. 进程分配内存的两种方式--brk() 和mmap()(不设计共享内存)(转)

    如何查看进程发生缺页中断的次数? 用ps -o majflt,minflt -C program命令查看. majflt代表major fault,中文名叫大错误,minflt代表minor faul ...

  7. 八十二:memcached之python操作memcached

    安装:pip install python-memcached 创建链接:mc = memcache.Client(['127.0.0.1:11211'], debug=True) 插入数据:mc.s ...

  8. oslo_db.sqlalchemy.engines连库

    _ mysql -uroot -pc1234 oslo_db.sqlalchemy.engines root@devstack2019:/etc/keystone# more keystone.con ...

  9. JavaScript(1)——编程真善美

    编程真善美 命名风格: 驼峰命名法 小驼峰法 变量一般用小驼峰法标识.驼峰法的意思是:除第一个单词之外,其他单词首字母大写:camelCase 大驼峰法(即帕斯卡命名法) 相比小驼峰法,大驼峰法把第一 ...

  10. js 视差滚动 记录备份

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...