A label event is typically written in this way, or it may be a binding event, in the same way:
1. <a href= "Web effects://" onclick= "dosomething ()" >a1</a>
2. <a href= "javascript:void (0)" onclick= "dosomething ()" >a2</a>
3. <a href= "###" onclick= "dosomething ()" >a3</a>
The third method DoSomething () in the switch picture completely no problem, but href= "###" but brought another problem, occupy the anchor point, the page URL is also not beautiful.
1th, 2 ways, although not the above problem, but will cause IE6 of strange bugs, dosomething () in the picture can not be loaded.
Just add a return false after dosomething ();
If it is a binding event, it also increases the return false at the end of the function;
See a JS picture switch effect
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<body>
<a href= "http://www.111cn.net/" > Webmaster special effects Network </a>
<button onclick= "Slider.next ()" > Next </button>
<script type= "Text/javascript" >
<!--
slider = {
Isie:true,
M_imagesource: [],
m_selidx:0,
M_direction:1,
M_mainviewer:null,
M_delaytimer:null,
M_delaytimer1:null,
M_curobj:null,
M_tarobj:null,
M_inited:false,
Init:function (IDs, W, H, W1, H1, p, T, S, source) {
This.isie = document.all? True:false;
This.canvaswidth = W;
This.canvasheight = h;
This.imagewidth = W1;
This.imageheight = H1;
This.m_percent = p;
This.m_top = t;
This.m_spacewidth = s;
This.writecanvas (ID);
for (Var i=0;i<source.length;i++)
{//Welcome to Webmaster effect nets, our web site is very good to remember, ZZ Webmaster, JS is JS special effects, this site collects a large number of High-quality JS code, there are many advertising code download.
this.container.innerhtml = ' }
This.m_mainviewer = This.container.firstchild.clonenode (true);
This.bind ();
This.start ();
},
Writecanvas:function (ID)
{//Welcome to Webmaster effect nets, our web site is very good to remember, ZZ Webmaster, JS is JS special effects, this site collects a large number of High-quality JS code, there are many advertising code download.
document.write (' <div id= "' +id+ '" style= "width: ' +this.canvaswidth+ ' px;height: ' +this.canvasheight+ ' px;position: Relative;overflow:hidden;background-color:black "></div>");
This.container = document.getElementById (ID);
},
Bind:function (obj, evt, fun) {
var obj = This.container;
for (Var i=0;i<obj.childnodes.length;i++)
{
This.attachevent (This.container.childnodes[i], "Mouseo tutorial ver", this.mouseover);
This.attachevent (This.container.childnodes[i], "mouseout", this.mouseout);
This.attachevent (This.container.childnodes[i], "click", This.click);
}//Welcome to Webmaster effects nets, our web site is very good to remember, ZZ Webmaster, JS is JS special effects, this site collects a large number of High-quality JS code, there are many advertising code download.
},
Attachevent:function (obj, evt, fun) {
if (Slider.isie)
{
Obj.attachevent ("On" +evt, fun)
}else
{
Obj.addeventlistener (evt, fun, false);
}
},
Mouseover:function (e)
{
if (!e) e=window.event;
var obj = E.srcelement | | E.target;
if (Slider.isie)
{
Obj.style.filter = "Alpha (opacity=80)";
}else{
obj.style.opacity = "0.8";
}
},
Mouseout:function (e)
{
if (!e) e=window.event;
var obj = E.srcelement | | E.target;
if (Slider.isie)
{
Obj.style.filter = "Alpha (opacity=50)";
}else{
Obj.style.opacity = "0.5";
}//Welcome to Webmaster effects nets, our web site is very good to remember, ZZ Webmaster, JS is JS special effects, this site collects a large number of High-quality JS code, there are many advertising code download.
},
Click:function (e)
{
if (!e) e=window.event;
var obj = E.srcelement | | E.target;
var mobj = Slider.m_mainviewer;
Slider.m_selidx = Obj.getattribute ("index");
Slider.m_curobj = Slider.m_mainviewer;
Slider.m_tarobj = obj;
Slider.m_delaytimer = Slider.fadein (200,5);
},
Start:function () {
var obj = This.m_mainviewer;
if (Slider.isie)
{
Obj.style.filter = "Alpha (opacity=100)";
}else{
obj.style.opacity = "1";
}
This.container.appendchild (This.m_mainviewer);
This.m_mainviewer.style.width = parseint (this.m_mainviewer.style.width) * (1+this.m_percent) + "px";
This.m_mainviewer.style.height = parseint (this.m_mainviewer.style.height) * (1+this.m_percent) + "px";
This.m_curobj = This.container.childnodes[this.m_selidx];
This.m_tarobj = This.m_mainviewer;
if (This.m_delaytimer) clearinterval (Slider.m_delaytimer);
This.m_delaytimer = This.fadein (200,5);
},
Next:function () {
var obj = This.container;
var mobj = This.m_mainviewer;
if (This.m_selidx = = obj.childnodes.length-2)
{
This.m_direction =-1;
}
if (this.m_selidx = 0)
{
This.m_direction = 1;
}
Slider.m_curobj = Mobj;
Slider.m_tarobj = Obj.childnodes[this.m_selidx];
This.m_delaytimer = This.fadein (200,5);
MOBJ.SRC = OBJ.CHILDNODES[THIS.M_SELIDX].SRC;
if (this.m_direction==-1) {
This.m_selidx--;
}else{
This.m_selidx + +;
}
},
Fadein:function (AA, AB) {
var obj = This.container;
With (This.m_curobj.style) {var T1 = parseint (left); var t3 = parseint (width); var t4 = parseint (height); var t5 = parseint (top );}
if (slider.m_inited)
{
var K1 = (T1-(This.canvaswidth-parseint (This.m_curobj.style.width))/2/ab;
var K3 = (T3-parseint (this.m_tarobj.style.width))/ab;
var K4 = (T4-parseint (this.m_tarobj.style.height))/ab;
var K5 = (T5-parseint (this.m_tarobj.style.top))/ab;
}else{
var K1 = (T1-(this.canvaswidth-this.imagewidth* (1+this.m_percent))/2/ab;
var K3 = (t3-this.imagewidth* (1+this.m_percent))/ab;
var K4 = (t4-this.imageheight* (1+this.m_percent))/ab;
var K5 = (This.imageheight * this.m_percent/2)/ab;
}
var mobj = This.m_mainviewer;
Return SetInterval (function () {if (ab<1) {
Clearinterval (Slider.m_delaytimer);
if (slider.m_inited) {
if (!slider.m_fadein)
{
Slider.m_curobj = Obj.childnodes[slider.m_selidx];
Slider.m_tarobj = Mobj;
MOBJ.SRC = OBJ.CHILDNODES[SLIDER.M_SELIDX].SRC;
Slider.m_fadein = true;
slider.m_inited = false;
Slider.m_delaytimer = Slider.fadein (200,10);
}else{
Slider.m_fadein = false;
Slider.m_inited = true;
}
}
Slider.m_inited = true;
Return
}
AB--;T1-=K1;T3-=K3;T4-=K4;T5-=K5;
if (Slider.m_fadein)
{
for (Var i=0;i<obj.childnodes.length-1;i++)
{
Obj.childnodes[i].style.left = (parseint (t1) + (slider.imagewidth + slider.m_spacewidth) * (I-SLIDER.M_SELIDX)) + "px";
}
}
With (Mobj.style) {left = t1 + ' px '; top = t5 + ' px '; width = t3 + ' px '; height = t4 + ' px ';}
}
, Aa/ab)
}
}
Slider.init (' AAA ', 500,400,250,200, 0.5, 100, 20, [
"/image/1.jpg",
"/image/2.jpg",
"/image/3.jpg",
"/image/4.jpg",
"/image/5.jpg",
"/image/1.jpg",
"/image/2.jpg",
"/image/3.jpg"
]);
-->
</script>
</body>