The example of this article tells JS to implement cool email address Add function method. Share to everyone for your reference. The implementation methods are as follows:
<title>js to implement cool email address add function </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>
<body>
<div id= "Content" >
<div id= "SendMail" >
<input name= "TextField" type= "text" id= "sendaddress" size= ">"
</div>
<div id= "Friendlist" >
<div id= "Tbaddrtree" >
<ul>
<li membername= "John" email= "zhangsan@163.com" ><nobr><a> John </a></nobr></li>
<li membername= "Dick" email= "lisi@1126.com" ><nobr><a> Dick </a></nobr></li>
<li membername= "Harry" email= "Wangwu@189.com" ><nobr><a> Harry </a></nobr></li>
</ul>
</div>
<div id= "Bxaddrfly" > </div>
</div>
</div>
<br/>
</body>
I hope this article will help you with your JavaScript programming.