peterS.: Wie den Code vereinfachen...

Beitrag lesen

gruss Bio, hallo Mauro,

Sup!

Du kannst ja mittels des JS-Prototypen-Konzepts eigene "Bildwechsel-Objekte" erzeugen, die dann eine Methode "toggle" haben, die ohne Parameter jeweils die richtigen Bilder auswechselt - oder so.

>>oder so<< wollte ich gleich mal ausprobieren,
   aber leider konnte ich "document.images" nicht
   zum prototyping ueberreden;

Bios vervollstaendigter Ansatz ohne prototypen
   sieht dann so aus:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
 <meta http-equiv="content-style-type" content="text/css" />
 <meta http-equiv="content-script-type" content="text/javascript" />
 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
 <title>newImageMethods.html</title>
 <script type="text/javascript">
 <!--
  function setNewImageMethods() {
  /* document.images.prototype.setHighligth = imgMouseOver;
   document.images.prototype.setToDefault = imgMouseOut;
   //
  funktioniert nicht - "document.images" laesst keinen prototypen zu !
  */
   for (var i=0;i<document.images.length;i++) {
    document.images[i].setHighligth = imgMouseOver;
    document.images[i].setToDefault = imgMouseOut;
   }
  // nachteil: weist diese methoden JEDEM image-objekt zu;
  }
  function imgMouseOver() {
   this.src = (this.src.substring(0,this.src.lastIndexOf(".")) + "h" + this.src.substring(this.src.lastIndexOf(".")));
  }
  function imgMouseOut() {
   this.src = (this.src.substring(0,this.src.lastIndexOf("h.")) + this.src.substring(this.src.lastIndexOf(".")));
  }
  /* bildungsvorschrift [image.src] fuer dieses beispiel:
   dafault   : "button3.gif"  - mache aus "xxxh.xxx" ein "xxx.xxx";
   heighlight: "button3h.gif" - mache aus "xxx.xxx" ein "xxxh.xxx";
  */
 //-->
 </script>
</head>

<body onload="setNewImageMethods()" bgcolor="#f5f5f5" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">
 <br />
 <br />
 <br />
 <br />
 <img src="http://selfhtml.teamone.de/javascript/beispiele/anzeige/button3.gif" width="130" height="30" alt="" title="" border="0" onmouseover="this.setHighligth()" onmouseout="this.setToDefault()" /><br />
 <img src="http://selfhtml.teamone.de/javascript/beispiele/anzeige/button2.gif" width="130" height="30" alt="" title="" border="0" onmouseover="this.setHighligth()" onmouseout="this.setToDefault()" /><br />
 <img src="http://selfhtml.teamone.de/javascript/beispiele/anzeige/button1.gif" width="130" height="30" alt="" title="" border="0" onmouseover="this.setHighligth()" onmouseout="this.setToDefault()" />
<!--
 netscape 4.x kann mit dem schluesselwort "this" nichts anfangen - der gewuenschte effekt bleibt aus;
//-->
</body>

</html>

by(t)e by(t)e - peterS. - pseliger@gmx.net
--
sh:| fo:) ch:? rl:| br:& n3:} n4:# ie:| mo:{ va:| de:[ zu:] fl:) ss:) ls:& js:)