繁体   English   中英

如何使用 JavaScript 动态更改 css 文件

[英]How do i dynamically change css files using JavaScript

所以我正在尝试使用 javascript 和 css 更改我的 html 页面的值,但遗憾的是它不起作用。 这是我的代码,请帮助我。

//display persons and their records
        for (const persoon of Object.values(data.recordedData)) {
            let  val = 1;
            let tr = document.createElement('tr');
            let thp =  document.createElement('th');

            thp.innerHTML = persoon.student;
            tr.appendChild(thp);

         // add person to dropbox
            let option = document.createElement("option");
            option.innerText = persoon.student;
            option.value = persoon.profile; 
            option.parameter = persoon;
            list.appendChild(option);
           
            for (const waarde  of Object.values(persoon.values) ) {
                let tdp = document.createElement('td');
                tdp.innerText = waarde;
                // change colors here
                if (waarde < 5) {
                    tdp.className = 'Rood';
                }else{
                    tdp.className = 'Groen';
                }
                tr.appendChild(tdp);
            }
            table.appendChild(tr);
            val++
        }    

也许试试这样!

let table = document.getElementById("table");
    let kheaders = document.getElementById("kheaders");
    let list = document.getElementById("list");
    document.getElementById('individual').className = 'hidden';
    let maanden = [];

    let getData = async() => {

        const res = await fetch('./data.json', {method: "GET"})
        return await res.json();
    }

    let displayData = data => {
        //display months

        for (const e of Object.values(data.recordedMonths)) {
            let th = document.createElement("th");
            th.innerText = e;
            th.id = e ; 
            kheaders.appendChild(th);
            maanden.push(e);
            
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM