Skip to content Skip to sidebar Skip to footer

Javascript Html Table Parsing

HTML &l

Solution 1:

Try this (jsfiddle), increment the cell index by 2 each time, and use the simpler td selector:

function method () {
    var year = document.getElementById("year").value;
    var month = document.getElementById("month").value;
    var data = new Date(year, month - 1, 1);
    var dataTable = document.getElementById("table");
    var cells = dataTable.querySelectorAll("td");

    for (var i = 0; i < cells.length; i+=2) {
        var mikro = cells[i].firstChild.data.split("-");
        var place = cells[i+1].firstChild.data;
        console.log(mikro, place);
        var yearMonth1 = mikro[0].split(".");
        var yearMonth2 = mikro[1].split(".");
        var data1 = new Date(yearMonth1[0], yearMonth1[1] - 1, 1);
        var data2 = new Date(yearMonth2[0], yearMonth2[1] - 1, 1);
        if (data1 <= data && data2 >= data) {
            alert(place);
        }
    }
}

Post a Comment for "Javascript Html Table Parsing"

1999.09-2007.06 Secondary School
2007.09-2011.06