JS實(shí)現(xiàn)很酷的EMAIL地址添加功能實(shí)例
本文實(shí)例講述了JS實(shí)現(xiàn)很酷的EMAIL地址添加功能的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<head>
<title>JS實(shí)現(xiàn)很酷的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程序設(shè)計(jì)有所幫助。
相關(guān)文章
js運(yùn)動(dòng)應(yīng)用實(shí)例解析
這篇文章主要針對js運(yùn)動(dòng)應(yīng)用進(jìn)行實(shí)例解析2015-12-12js實(shí)現(xiàn)網(wǎng)頁多級級聯(lián)菜單代碼
這篇文章主要介紹了js實(shí)現(xiàn)網(wǎng)頁多級級聯(lián)菜單代碼,涉及javascript基于數(shù)組動(dòng)態(tài)構(gòu)造多級級聯(lián)菜單的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08BootStrap Fileinput上傳插件使用實(shí)例代碼
這篇文章主要介紹了BootStrap Fileinput上傳插件使用實(shí)例代碼,,通過引入js和css文件,具體實(shí)現(xiàn)代碼大家參考下本文2017-07-07Javascript獲取隨機(jī)數(shù)的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狫avascript獲取隨機(jī)數(shù)的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06bootstrap-treeview實(shí)現(xiàn)多級樹形菜單 后臺JSON格式如何組織?
這篇文章主要介紹了bootstrap-treeview實(shí)現(xiàn)多級樹形菜單,后臺JSON格式如何組織,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07JS實(shí)現(xiàn)去除數(shù)組中重復(fù)json的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)去除數(shù)組中重復(fù)json的方法,涉及javascript針對json數(shù)組數(shù)據(jù)的遍歷、判斷、存取等相關(guān)操作技巧,需要的朋友可以參考下2017-12-12