Este exemplo de artigo descreve como o JS implementa uma função legal de adição de endereço de e -mail. Compartilhe para sua referência. O método de implementação específico é o seguinte:
Copie o código da seguinte forma: <html>
<head>
<título> JS implementa a função de adição de endereço de e -mail legal </ititle>
<style type = "text/css">
Ul {estilo de lista: nenhum; margem: 0; preenchimento: 0;}
li {margem: 0; preenchimento: 0;}
#Content {Width: 100%;}
#sendmail {float: esquerda; Largura: 60%;}
#friendlist {float: esquerda; Largura: 30%;}
#bxaddrfly {posição: absoluto; altura: 18px; Largura: 46px; fundo: #EEE; Border: 1px #ccc sólido; display: nenhum;}
#tbaddrtree {width: 126px; flutuar: esquerda; preenchimento: 5px; borda: 1px #7f9db9 sólido;}
#tbaddrtree li {width: 100%; Float: Esquerda;}
#tbaddrtree a {backgroud: #fff; largura: 100%; cor: #494949; decoração de texto: nenhum; float: esquerda;}
#tbaddrtree a: hover {background: #e5edf6;}
</style>
<script type = "text/javascript">
var ev = {};
var flydiv = "bxaddrfly";
var intoCceptDiv = "sendAddress";
var addEvent = "addaddress ()";
function oo (obj) {return (document.getElementById)? document.getElementById (OBJ): document.all [obj];}
função isNone (str) {return str == null || str == ""? true: false}
VAR navegador = new Object ();
Browser.isfirefox = (Navigator.UserAgent.TolowerCase (). Indexof ("Firefox")! =-1);
if (navegador.isfirefox) {extendeventobject ();}
função estendeventoBject () {
window.constructor.prototype .__ Definegetter __ ("Evento", function () {
var o = argumentos.callee.caller;
var e;
while (o! = null) {
E = O. Argumentos [0];
if (e && (e.Constructor == Event || e.Constructor == Mouseevent)) retornar e;
o = o.caller;
}
retornar nulo;
});
Event.Prototype .__ Definegetter __ ("SRCELEMENT", function () {
var node = this.target;
while (node.nodeType! = 1) node = node.parentNode;
Nó de retorno;
});
}
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)};
}
função addrtree_event (e) {
var membroid, tr
var ee = e.srcelement;
if (ee.tagname == "a" && e.type == "mouseOver") {ee.style.textDecoration = "sublinhado"}
if (ee.tagname == "a" && e.type == "mouseout") {ee.style.textDecoration = ""}
if (e.type == "clique" && e.srcelement.tagname == "a") {
var li = ee.parentnode.parentNode;
ev.addinfo = "/" "+li.getAttribute (" MemberName ")+"/"</" "+li.getAttribute (" email ")+"/">"
oo (flydiv) .innerhtml = li.getAttribute ("membro do nome");
addrtree_add (e.clientX, e.clienty)
}
}
função addrtree_add (ex, ey) {
if (oo (flydiv) .style.display == 'none' || oo (flydiv) .style.display == '') {oo (flydiv) .style.display = 'bloco';}
var decepte = oo (INCEPTDIV);
var INCECTEX = INCEPTE.OFFSETTOP;
var INCEPTEY = INCEPTE.OFFSETLEFT;
while (INCEPTE = INCEPTE.OFFSETPARENT) {
INCECTEX += INCEPTE.OFFSETTOP;
INCEPTEY += INCEPTE.OFFSETLEFT;
}
Ev.flyarr = nova matriz (ex, ey, INCEPTEX, INCEPTEY, 10);
voar (flydiv, addEvent);
}
Função 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;
retornar;
}
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)
}
função addaddress ()
{
var key = ev.addinfo;
if (oo (INCECTDIV) .VALUE.IndexOf (key) ==-1)
{
OO (INCECTDIV) .VALUE+= KEY+",";
}
}
</script>
</head>
<Body>
<div id = "content">
<div id = "sendmail">
<input name = "textfield" type = "text" id = "sendAddress" size = "70">
</div>
<div id = "amigas">
<div id = "tbaddrtree">
<ul>
)
<li membroName = "li si" email = "[email protected]"> <br> <a> li si </a> </br> </li>
<li membroName = "wangwu" email = "[email protected]"> <br> <a> Wangwu </a> </br> </li>
</ul>
</div>
<div id = "bxaddrfly"> </div>
</div>
</div>
<br />
</body>
</html>
Espero que este artigo seja útil para a programação JavaScript de todos.