1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| <html>
<head>
<title>Les déclarations d'objets en JavaScript</title>
<style type="text/css">
div#poissons {
vertical-align: top;
}
div.poisson {
display: inline-block;
font-family: arial;
font-size:14px;
padding:4px;
margin:2px;
border:1px solid #009;
width:310px;
height: 350px;
}
h1 {
font-size:16px;
font-weight: bold;
}
span.latin {
font-style: italic;
font-size:12px;
}
span.noms {
font-size:13px;
}
div.poisson div.image {
width:310px;
height:200px;
line-height:200px;
vertical-align: middle;
display: table-cell;
margin-top:5px;
}
div.poisson img {
max-height:200px;
max-width: 300px;
margin:auto;
vertical-align: middle;
padding:auto;
}
div.particularite {
padding-top: 5px;
padding-bottom: 5px;
height: 30px;
}
</style>
</head>
<body>
<div id="poissons"></div>
<script type="text/javascript">
function displayTruite() {
var html="<div class='poisson'><h1>"+this.nom;
html+="<span class='latin'> ("+this.latin+")</span></h1>";
html+="<span class='noms'>"+this.noms.join(", ")+"</span>";
html+="<div class='image'><img src='bureau/"+this.image+"' /></div>";
html+="<div class='particularite'>"+this.particularite+"</div>";
html+="<div>Taille moyenne : "+this.tailleMoyenne+" cm</div>";
html+="<div>Taille maxi : "+this.tailleMaxi+" cm</div></div>";
return html;
}
var truiteFario={
nom: "Fario",
noms: ["Truite sauvage","Truite commune"],
latin: "salmo truta fario",
image: "fario.jpeg",
particularite: "Présence de points rouges et noirs auréolés",
tailleMoyenne: 30,
tailleMaxi: 70,
display:displayTruite,
}
var truiteArcEnCiel=new Object();
truiteArcEnCiel.nom="Arc en ciel";
truiteArcEnCiel.latin="salmo gairdneri";
truiteArcEnCiel.image="arcenciel.jpeg";
truiteArcEnCiel.noms=new Array("Truite d'élevage", "Truite d'Amérique");
truiteArcEnCiel.particularite="Poisson originaire des Etats-Unis et introduit en France";
truiteArcEnCiel.tailleMoyenne=30;
truiteArcEnCiel.tailleMaxi=80;
truiteArcEnCiel.display=displayTruite;
function Truite(nom, latin, image, noms, partic, tMoyenne, tMaxi) {
this.nom=nom;
this.latin=latin;
this.image=image;
this.noms=noms;
this.particularite=partic;
this.tailleMoyenne=tMoyenne;
this.tailleMaxi=tMaxi;
this.display=displayTruite;
}
var saumonFontaine=new Truite("Saumon de fontaine", "salvinilus fontanilis", "omble.jpeg", ["Omble"], "Présence de points orange et noirs auréolés", 25, 50);
class Poisson {
constructor(nom, latin, image, noms, partic, tMoyenne, tMaxi) {
this.nom=nom;
this.latin=latin;
this.image=image;
this.noms=noms;
this.particularite=partic;
this.tailleMoyenne=tMoyenne;
this.tailleMaxi=tMaxi;
this.display=displayTruite;
}
}
var truiteMer=new Poisson("Truite de mer", "salmo truta truta", "truitemer.jpeg", ["Truite argentée"], "Migratrice de l'Atlantique vers cours d'eau pour la reproduction", 35, 100);
document.getElementById("poissons").innerHTML=truiteFario.display()+truiteArcEnCiel.display()+saumonFontaine.display()+truiteMer.display();
</script>
</body>
</html> |
Partager