Solucio michelin

De wikiserver
La revisió el 19:23, 30 oct 2015 per Asalinas (Discussió | contribucions)
(dif) ← Versió més antiga | Versió actual (dif) | Versió més nova → (dif)
Dreceres ràpides: navegació, cerca

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>