Vorlage:Inventory

Aus Meddlerde
Version vom 3. März 2025, 11:55 Uhr von Xeada (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Inventory == <div style="border: 2px solid #4CAF50; padding: 10px; background-color: #f9f9f9; border-radius: 10px; font-family: 'Roboto', sans-serif; width: 45%; float: left; margin-right: 20px; position: sticky; top: 0;"> <h2 style="color: #4CAF50; text-align: center; margin-top: 5px; margin-bottom: 5px;">Inventory</h2> <table id="inventoryTable" style="width: 100%; border-collapse: collapse; margin-bottom: 5px; font-size: 11px;"> <the…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Inventory

Inventory

<thead> </thead> <tbody> </tbody>
Item Name Quantity Weight Description Category
Longsword 1 3 lbs A versatile weapon Weapon
Backpack 1 5 lbs A sturdy backpack Gear

<script> function sortTable(n) {

   var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
   table = document.getElementById("inventoryTable");
   switching = true;
   dir = "asc"; 
   while (switching) {
       switching = false;
       rows = table.rows;
       for (i = 1; i < (rows.length - 1); i++) {
           shouldSwitch = false;
           x = rows[i].getElementsByTagName("TD")[n];
           y = rows[i + 1].getElementsByTagName("TD")[n];
           if (dir == "asc") {
               if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
                   shouldSwitch = true;
                   break;
               }
           } else if (dir == "desc") {
               if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
                   shouldSwitch = true;
                   break;
               }
           }
       }
       if (shouldSwitch) {
           rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
           switching = true;
           switchcount++;
       } else {
           if (switchcount == 0 && dir == "asc") {
               dir = "desc";
               switching = true;
           }
       }
   }

} </script>