JS实现很酷的EMAIL地址添加功能实例

作者:代码家园 时间:2024-11-20 11:21:15 

本文实例讲述了JS实现很酷的EMAIL地址添加功能的方法。分享给大家供大家参考。具体实现方法如下:

<html>
<head>
<title>JS实现很酷的EMAIL地址添加功能</title>
<style type="text/css">
ul{ list-style:none; margin:0; padding:0;}
li{ margin:0; padding:0;}
#content{width:100%;}
#sendmail{float:left; width:60%;}
#friendlist{float:left; width:30%;}
#bxAddrFly{position:absolute;height:18px; width:46px;background:#EEE; border:1px #ccc solid;display:none;}
#tbAddrTree{ width:126px; float:left; padding:5px;border:1px #7F9DB9 solid;}
#tbAddrTree li{ width:100%; float:left;}
#tbAddrTree a{backgroud: #fff;width: 100%;color:#494949;text-decoration: none;float:left;}
#tbAddrTree a:hover{background: #e5edf6;}
</style>
<script type="text/javascript">
var ev={};
var flyDiv="bxAddrFly";
var inceptDiv="SendAddress";
var addEvent="addAddress()";
function oo(obj){return (document.getElementById) ? document.getElementById(obj): document.all[obj];}
function isNone(str){return str==null||str==""?true:false}
var Browser = new Object();
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
if (Browser.isFirefox) { extendEventObject();}
function extendEventObject() {
window.constructor.prototype.__defineGetter__("event", function(){
var o = arguments.callee.caller;
var e;
while(o != null){
e = o.arguments[0];
if(e && (e.constructor == Event || e.constructor == MouseEvent)) return e;
o = o.caller;
}
return null;
});

Event.prototype.__defineGetter__("srcElement", function () {
var node = this.target;
while (node.nodeType != 1) node = node.parentNode;
return node;
});
}
window.onload = function(){
var addrTree = oo('tbAddrTree');
addrTree.onmouseover = function(){addrTree_event(event)};
addrTree.onmouseout = function(){addrTree_event(event)};
addrTree.onclick = function(){addrTree_event(event)};
}
function addrTree_event(e){
var memberID,tr
var ee = e.srcElement;
if(ee.tagName=="A"&&e.type=="mouseover"){ee.style.textDecoration="underline"}
if(ee.tagName=="A"&&e.type=="mouseout"){ee.style.textDecoration=""}
if(e.type=="click"&&e.srcElement.tagName=="A"){
var li=ee.parentNode.parentNode;
ev.AddInfo="\""+li.getAttribute("memberName")+"\"<\""+li.getAttribute("email")+"\">"
oo(flyDiv).innerHTML=li.getAttribute("memberName");
addrTree_add(e.clientX,e.clientY)
}
}
function addrTree_add(ex,ey){
if(oo(flyDiv).style.display=='none'||oo(flyDiv).style.display==''){oo(flyDiv).style.display='block';}
var inceptE = oo(inceptDiv);
var inceptEX = inceptE.offsetTop;  
var inceptEY = inceptE.offsetLeft;  
while(inceptE = inceptE.offsetParent){
inceptEX += inceptE.offsetTop;  
inceptEY += inceptE.offsetLeft;  
}
ev.flyArr=new Array(ex,ey,inceptEX,inceptEY,10);
fly(flyDiv,addEvent);
}

function fly(flyObj,flyRun){
var obj,a=ev.flyArr,x,y
if(flyObj!=null){
if(ev.flyObj!=null){
window.clearTimeout(ev.flyTm);
ev.flyObj.style.top=-900;
}
a[5]=0;
ev.flyObj=oo(flyObj);
ev.flyRun=flyRun;
}

obj=ev.flyObj;
if(a[4]==null){a[4]=1}
a[5]+=a[4]/Math.sqrt(Math.pow(a[2]-a[0],2)+Math.pow(a[3]-a[1],2));
if(a[5]>1){
obj.style.top=-900;
eval(ev.flyRun);
ev.flyObj=null;
return;
}

window.clearTimeout(ev.flyTm);
x=(a[2]-a[0])*a[5]+a[0];
y=(a[3]-a[1])*a[5]+a[1];
obj.style.left=x;
obj.style.top=y;
document.body.style.overflowX="hidden";
ev.flyTm=window.setTimeout("fly()",10)
}

function addAddress()
{
var key=ev.AddInfo;
if (oo(inceptDiv).value.indexOf(key)==-1)
{
oo(inceptDiv).value+=key+",";
}
}
</script>
</head>
<body>
<div id="content">
  <div id="sendmail">
    <input name="textfield" type="text" id="SendAddress" size="70">
  </div>
  <div id="friendlist">
    <div id="tbAddrTree">
      <ul>
        <li membername="张三" email="zhangsan@163.com"><nobr><a>张三</a></nobr></li>
        <li membername="李四" email="lisi@1126.com"><nobr><a>李四</a></nobr></li>
        <li membername="王五" email="wangwu@189.com"><nobr><a>王五</a></nobr></li>
      </ul>
    </div>
    <div id="bxAddrFly"> </div>
  </div>
</div>
<br />
</body>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

标签:JS,EMAIL,添加,功能
0
投稿

猜你喜欢

  • python调用DLL与EXE文件截屏对比分析

    2022-06-01 08:19:15
  • Mysql数据库性能优化一

    2024-01-20 17:06:45
  • 设置iframe的document.designMode后仅Firefox中其body.innerHTML为br

    2024-05-02 16:17:31
  • 用pandas中的DataFrame时选取行或列的方法

    2023-05-15 07:43:04
  • Python中使用ConfigParser解析ini配置文件实例

    2021-06-18 01:41:44
  • MySQL 原理与优化之Limit 查询优化

    2024-01-15 04:44:26
  • Python截取字符串的简单方法实例

    2023-02-20 04:54:01
  • python合并文本文件示例

    2021-05-08 01:24:49
  • python中判断数字是否为质数的实例讲解

    2022-02-17 13:19:05
  • python中使用smtplib和email模块发送邮件实例

    2022-09-16 05:37:23
  • 图文详解OpenCV中光流以及视频特征点追踪

    2022-12-30 01:45:08
  • js前端实现登录拼图验证功能

    2024-04-19 10:45:29
  • Django多层嵌套ManyToMany字段ORM操作详解

    2023-07-01 02:26:28
  • 详解Python的三种可变参数

    2022-06-18 03:09:27
  • 利用Pycharm将python文件打包为exe文件的超详细教程(附带设置文件图标)

    2021-12-06 18:06:24
  • python 窃取摄像头照片的实现示例

    2021-12-27 19:16:11
  • Flask框架的学习指南之制作简单blog系统

    2022-09-28 03:27:26
  • PHP实现简易计算器功能

    2024-05-11 09:25:27
  • Python脚本暴力破解栅栏密码

    2022-02-09 18:31:11
  • MySQL数据库搜索中的大小写敏感性

    2008-11-24 12:44:00
  • asp之家 网络编程 m.aspxhome.com