0

我有一个 PHP 脚本,它生成一个 HTML 表,如下所示:

此表显示添加到文具的库存的详细信息。

Item   | Quantity | Date    
------------------------------
Pencil | 100      | 2013-02-01  
Pencil | 100      | 2013-02-01  
Rubber | 100      | 2013-02-02  

现在,我希望一些客户端脚本仅显示位于两个日期之间的那些行。我该怎么做?请帮忙。

谢谢。

4

2 回答 2

0

您可以使用 javascript 或 jQuery 脚本来检查日期单元格中的值,如果它不符合条件,则可以隐藏该行。

<table>
    <tr id="table-row-1">
        <td id="item-cell-1">
            Pencil
        </td>
        <td id="quantity-cell-1">
            100
        </td>
        <td id="date-cell-1">
            2013-02-01
        </td>
    </tr>
    etc...

jQuery

for(var i=0;i<count;i++) {
    var cellDate = Date.parse($("date-cell-" + i).text());
    //Check if date is between what your want, if not then hide
    $("table-row-" + i).empty(); //or you could hide using css display:none;
}
于 2013-02-02T05:37:42.080 回答
0

[1]:https: //i.stack.imgur.com/I1WOv.png

这是代码

function myFunction() {

  var input1,input2, filter, table, tr, td, i;
  input1 = document.getElementById("dateStart").value;
  input2 = document.getElementById("dateEnd").value;
  table = document.getElementById("question1-list");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[4].innerHTML;
    var d1=input1.split("-");
    var d2=input2.split("-");
    var c=td.split("-");
    var from=new Date(d1[0],parseInt(d1[1])-1,d1[2]);
    var to   = new Date(d2[0], parseInt(d2[1])-1, d2[2]);
    var check = new Date(c[0], parseInt(c[1])-1, c[2]);
   if(check>=from && check<=to)
   {

    tr[i].style.display = "";
   }
   else
   {

    tr[i].style.display = "none";
   }


  }
}
于 2017-05-30T07:06:00.607 回答