is it possible to add two values for the mouseOver command?
i want two things to happen when i move the mouse over an im开发者_如何学Cage, is there a way to write the code that way?
<a href="http://google.com/" target="_new"
onMouseOver="MM_swapImage('301','','/w/w-1.gif',1)"
onMouseOut="MM_swapImgRestore()">
this is the original code for general rollover images in dreamweaver, but i want to add more to onMouseOut=
and Over=
like onMouseOut="MM_swapImgRestore()";"some command"
or how can i write this? im using javascript
i appreciate any help!
The onMouse* properties usage is deprecated in modern browsers. You should use addEventListener or something corresponding instead. These 'listeners'-based implementations allow to add as much event-handlers as you want to any event.
I don't remember exact cross-browser syntax for this, but you can see it inside the the source code of any popular JS framework (like jQuery or Prototype or MooTools), or just use this framework.
Ofcourse it's possible to do something like:
onMouseOver="func1();func2();func3();"
But it's a bad-practice because this approach is incompatible with much of third-party JavaScript libraries you probably will use.
Have it call a function that calls both functions.
EDIT It's even easier. Just do
onMouseOver="func1(); func2()"
Using the idea of Vadim, you can do this:
// Others (Chrome, Firefox, etc)
document.addEventListener("mouseover",function(){thingone(); thingtwo();},false);
// IE
document.attachEvent("onmouseover",function(){thingone(); thingtwo();});
PS: Shall I quote cdhowie too, for the function names?
精彩评论