简体   繁体   中英

How to add present month dates as Headers for each individual column in html table using javascript?

Am unsatified with the other answers with realted question asked by me. i want each column header of a html to be displayed with a individual date when web page is loaded to that specific month in javascript . I tried but i got no success. Here is my javascript code.

function addRows(table, dates) {
        var idx = 1;
        for (var i in dates) {
            table.append(
                         '<th><input name="date'+idx+'" id="date'+idx+'" class="date" value="'+dates[i]+'"></th>'
             );
            idx++;
        }
    }

    $(function() {
        var myDate = new Date();
        var year   = myDate.getFullYear();
        var month  = myDate.getMonth(); 
        var dates  = myDate.daysInMonth(year, month);
        var table  = $("#myTable").find("tbody");
        addRows(table, dates);
    });`

link below will show you the code to create an array wit each date in it.

Find all the days in a month with Date object?

you could then map over the array creating a table header for each item in the array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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