【发布时间】:2020-06-15 09:22:09
【问题描述】:
您好,我想知道如何根据来自两个日期选择器输入值的日期期间或天数动态增加表列,并将日期作为列的标题。我用它来过滤数据库中的数据以建立考勤样本。 以下是创建表格标题单元格但使用按钮的代码
<!DOCTYPE html>
<html>
<head>
<style>
table, th {
border: 1px solid black;
}
</style>
</head>
<body>
<table id="myTable">
<tr id="myTr">
</tr>
</table>
<p>Click the button to create a TH element.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.createElement("TH");
var t = document.createTextNode("table header cell");
x.appendChild(t);
document.getElementById("myTr").appendChild(x);
}
</script>
</body>
</html>
以及下面的代码我如何获得 2 个日期选择器值,但不知道如何计算这些值之间的时间段以及如何将其作为列增加的逻辑注入
<!DOCTYPE html>
<html>
<body>
<h3>A demonstration of how to access a Date field</h3>
<input type="date" id="startdate" value="2014-02-09">
<br>
<input type="date" id="enddate" value="2014-02-09">
<p>Click the button to get the date of the date field.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> input elements with type="date" do not show as any date field/calendar in IE 11 and earlier versions.</p>
<p id="demo"></p>
<br>
<p id="demo1"></p>
<script>
function myFunction() {
var x = document.getElementById("startdate").value;
document.getElementById("demo").innerHTML = x;
var x = document.getElementById("enddate").value;
document.getElementById("demo1").innerHTML = x;
}
</script>
</body>
</html>
谢谢你的提前
【问题讨论】: