我有一个按预期工作的表格,显示开始日期和结束日期之间的所有数据(请查看评论以获取更多信息)。我现在遇到的唯一问题是,当我单击表格上的“下一个”按钮时,表格标题将日期移动到下周日期并显示该周的数据,但它也显示上周的数据。我需要的是,如果它转到下周日期,它应该仅显示该周的数据(没有上周的行/数据)。
//this is only an eg:
function test() {
//this is the table header start date(in pic)6/4/17
var test1 = document.getElementById("testing").innerHTML;
//this is the table header close date(in pic)6/10/17
var test2 = document.getElementById("testin").innerHTML;
//this is the function if dates is between start and end its displays the data in a tabel
function dateInRange(dbdates, start, end) {
if (end >= dbdates && start <= dbdates) {
return true;
} else {
return false;
}
}
var columns = ['orange']
var table = document.getElementById('tablet');
for (var i = 0; i < (testvalues.length - 1); i = i + 5) { //looping all values from db
if (dateInRange(testvalues[i + 2], test1, test2)) {
var row = table.insertRow(-1);
var cell1 = row.insertCell(-1);
var cell2 = row.insertCell(-1);
//more logic
//this is just an ex:
//this is next button on table
$("next").click(
test();
}
最佳答案
您需要在 dateInRange 函数的开头添加类似以下内容:
function dateInRange(dbdates, start, end) {
dbdates=Date(dbdates);
start=Date(start);
end=Date(end);
//rest of function
}
这将允许您进行您尝试的日期比较。您可以在将值传递给函数之前将其转换为日期,但这可以使您的代码更加简洁。
关于删除/替换除标题之外的所有现有行,这里有一个很好的解决方案:Delete all rows in an HTML table
关于javascript - 表格显示数据超出范围,js jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44461586/