Diferència entre revisions de la pàgina «Solucio michelin»
De wikiserver
| (5 revisions intermèdies per un altre usuari que no es mostra) | |||
| Línia 1: | Línia 1: | ||
| − | <source lang=" | + | Fitxer menu.js: |
| − | var | + | <source lang="javascript"> |
| − | var | + | var camSel = 1; |
| − | var | + | var total1 = 0; |
| + | var total2 = 0; | ||
| − | function | + | window.onload = function() { |
| − | { | + | document.getElementById("c1").onclick = seleccionarCam; |
| − | + | document.getElementById("c2").onclick = seleccionarCam; | |
| − | + | document.getElementById("1").onclick = seleccionTapa; | |
| − | + | document.getElementById("2").onclick = seleccionTapa; | |
| − | + | document.getElementById("3").onclick = seleccionTapa; | |
| − | + | document.getElementById("4").onclick = seleccionTapa; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| + | function seleccionarCam(evento) { | ||
| + | var e = evento || window.event; | ||
| − | + | camSel = e.currentTarget.value; | |
| − | + | } | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | function seleccionTapa(evento) { | ||
| + | var e = evento || window.event; | ||
| + | if (camSel == 1) { | ||
| + | total1 += parseInt(e.currentTarget.id); | ||
} | } | ||
| − | + | else { | |
| − | + | total2 += parseInt(e.currentTarget.id); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| + | document.getElementById("info" + camSel).innerHTML += "<br>Tapa" + | ||
| + | e.currentTarget.id + ": " + e.currentTarget.id + "€"; | ||
| + | document.getElementById("total" + camSel).innerHTML = (camSel==1)? total1 : total2; | ||
} | } | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</source> | </source> | ||
| + | Fitxer index.html: | ||
<source lang="html"> | <source lang="html"> | ||
<html> | <html> | ||
<head> | <head> | ||
| − | + | <meta charset="UTF-8"/> | |
| − | <meta charset="UTF-8" | + | <script type="text/javascript" src="js/menu.js"></script> |
| − | + | <style type="text/css"> | |
| − | <script type="text/javascript" src=" | + | html |
| − | < | + | { |
| + | font-family: "courier new"; | ||
| + | } | ||
| + | </style> | ||
</head> | </head> | ||
| − | <body> | + | <body > |
| − | < | + | <img id = "1" src="imagenes/1.png" alt="tapa 1" /> |
| − | + | <img id = "2" src="imagenes/2.png" alt="tapa 2"/> | |
| − | + | <img id = "3" src="imagenes/3.png" alt="tapa 3"/> | |
| − | + | <img id = "4" src="imagenes/4.png" alt="tapa 4"/> | |
| − | + | <button id="c1" value="1">Camarero 1</button> | |
| − | + | <button id="c2" value="2">Camarero 2</button> | |
| − | + | <div id="info1">Tapas servidas por el camarero1:</div> | |
| − | < | + | <div id="total1"></div> |
| − | + | <div id="info2">Tapas servidas por el camarero2:</div> | |
| − | + | <div id="total2"></div> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | </div> | ||
</body> | </body> | ||
</html> | </html> | ||
</source> | </source> | ||
Revisió de 18:23, 30 oct 2015
Fitxer menu.js:
var camSel = 1;
var total1 = 0;
var total2 = 0;
window.onload = function() {
document.getElementById("c1").onclick = seleccionarCam;
document.getElementById("c2").onclick = seleccionarCam;
document.getElementById("1").onclick = seleccionTapa;
document.getElementById("2").onclick = seleccionTapa;
document.getElementById("3").onclick = seleccionTapa;
document.getElementById("4").onclick = seleccionTapa;
}
function seleccionarCam(evento) {
var e = evento || window.event;
camSel = e.currentTarget.value;
}
function seleccionTapa(evento) {
var e = evento || window.event;
if (camSel == 1) {
total1 += parseInt(e.currentTarget.id);
}
else {
total2 += parseInt(e.currentTarget.id);
}
document.getElementById("info" + camSel).innerHTML += "<br>Tapa" +
e.currentTarget.id + ": " + e.currentTarget.id + "€";
document.getElementById("total" + camSel).innerHTML = (camSel==1)? total1 : total2;
}
Fitxer index.html:
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="js/menu.js"></script>
<style type="text/css">
html
{
font-family: "courier new";
}
</style>
</head>
<body >
<img id = "1" src="imagenes/1.png" alt="tapa 1" />
<img id = "2" src="imagenes/2.png" alt="tapa 2"/>
<img id = "3" src="imagenes/3.png" alt="tapa 3"/>
<img id = "4" src="imagenes/4.png" alt="tapa 4"/>
<button id="c1" value="1">Camarero 1</button>
<button id="c2" value="2">Camarero 2</button>
<div id="info1">Tapas servidas por el camarero1:</div>
<div id="total1"></div>
<div id="info2">Tapas servidas por el camarero2:</div>
<div id="total2"></div>
</body>
</html>