Untitled

mail@pastecode.io avatar
unknown
html
7 months ago
2.4 kB
7
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table,tr,td,th{
            border:1px solid;
            border-collapse:collapse;
        }
        tr{
            width:30px;
        }
    </style>
</head>
<body>

    <table>
        <th>nazwa </th><th>ilosc</th><th>aktualizuj</th><th>zamówienie</th>
        <tr><td class="klasa1">a</td><td>11</td><td><input type="button" onclick="zmiana()" value="zmien"></td><td><input type="button" onclick="zamów(1)" value="zamow"></td> </tr>
        <tr><td id="test1">b</td><td>3</td><td><input type="button" onclick="zmianatest1()" value="zmien"></td><td><input type="button" onclick="zamów(2)" value="zamow"></td> </tr>
        <tr><td class="klasa1">c</td><td class="klasa1">3</td><td><input type="button" onclick="zmianaklasa1()" value="zmien"></td><td><input type="button" onclick="zamów(3)" value="zamow"></td> </tr>
        <tr><td >d</td><td >43</td><td><input type="button" onclick="zmianaqall()" value="zmien"></td><td><input type="button" onclick="zamów(4)" value="zamow"></td> </tr>
    </table>
    <input type="button" onclick="czymalo()">

    <script>
        function czymalo(){
            let analizowana = document.querySelectorAll("td");
            for(let i =1;i<analizowana.length;i=i+4){
                wartosckomorki=parseInt(analizowana[i].textContent)
                if (wartosckomorki>10){
                    analizowana[i].style.backgroundColor="green";
                }
                else{
                    analizowana[i].style.backgroundColor="red";
                }
            }
        }

        function zmiana(){
            document.querySelector("td").style.backgroundColor="green";
        }

        function zmianatest1(){
            document.querySelector("#test1").style.backgroundColor="red";
        }
        function zmianaklasa1(){
            document.querySelector(".klasa1").style.backgroundColor="yellow";
        }
        function zmianaqall(){
            let komorka=document.querySelectorAll("td");
            for(let i=0;i<komorka.length; i++){
                komorka[i].style.backgroundColor="blue";    
            }
          }
    </script>
    
</body>
</html>