javascript - 表格显示数据超出范围,js jquery

标签 javascript jquery

我有一个按预期工作的表格,显示开始日期和结束日期之间的所有数据(请查看评论以获取更多信息)。我现在遇到的唯一问题是,当我单击表格上的“下一个”按钮时,表格标题将日期移动到下周日期并显示该周的数据,但它也显示上周的数据。我需要的是,如果它转到下周日期,它应该仅显示该周的数据(没有上周的行/数据)。

enter image description here

//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/

相关文章:

javascript - SVG for Web 中的长阴影效果

jquery - 在 Mocha 测试中使用 jQuery,使用 Node 而不是 io.js

javascript - 如果第 nth-child 为 1 或 2,则右对齐菜单

javascript - Angular js $http 服务 :- header is not accessible inside catch block

javascript - 我被困在 multiplicativePersistence 算法问题上。我不知道为什么这段代码不起作用

javascript - 单个函数的多个元素

jquery - Angular js : camera slideshow jquery plugin is not working in partial view

jquery - 如何隐藏 jqGrid 子网格上的水平滚动条?

javascript - 检测浏览器或标签关闭

php - 自定义表单验证和提交