gpt4 book ai didi

javascript - 通过选择日期选择器创建数据表标题

转载 作者:行者123 更新时间:2023-11-29 10:41:10 26 4
gpt4 key购买 nike

我尝试创建带有动态列的数据表,用于从/到日期选择器中进行选择。

列应该包含日期和 toDate 之间的 fromDate

JS代码

$("#from").datepicker();
$("#to").datepicker();

var strTopHead='<th rowspan="2">Name</th><th rowspan="2">Code</th><th rowspan="2">code</th>';

$('#getBetween').on('click', function () {

$('#trTopHead').empty();
$('#trBottomHead').empty();
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate"),
currentDate = new Date(start),
between = []
;
if(start!=null&&end!=null){
while (currentDate <= end) {
between.push(new Date(currentDate).toJSON().substring(0,10));
currentDate.setDate(currentDate.getDate() + 1);
}

// $('#results').html(between.join('<br> '));
for(var i=0;i<between.length;i++){
strTopHead=strTopHead+'<th colspan="3">'+between[i]+'</th>';

$('#trBottomHead').append('<th>C</th><th>D</th> <th>E</th>');
$('table>tbody').append('<tr><td>Tiger Nixon</td> <td>System Architect</td> <td>$320,800</td> <td>Edinburgh</td> <td>5421</td> <td>t.nixon@datatables.net</td></tr>');
}
$('#trTopHead').append(strTopHead);

$('#example').dataTable({
"scrollY": "200px",
"scrollCollapse": true
});
}
});

这里只显示单个日期作为列

I tried like this

最佳答案

我已经对你的代码做了一些修改

var date= new Date();//changes
$("#from").datepicker();
$("#to").datepicker();

$("#from").val($.datepicker.formatDate("mm/dd/yy",date));//changes
$("#to").val($.datepicker.formatDate("mm/dd/yy",date));//changes


$('#getBetween').on('click', function () {
var strTopHead='';
$('#trTopHead').empty();
$('#trBottomHead').empty();
strTopHead=strTopHead+ '<th rowspan="2">Name</th><th rowspan="2">Code</th><th rowspan="2">code</th>';
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate"),
currentDate = new Date(start),
between = []
;
if(start!=null&&end!=null){
while (currentDate <= end) {
currentDate.setDate(currentDate.getDate() + 1);//changes
between.push(new Date(currentDate).toJSON().substring(0,10));//changes

}
var strTopHeadDates='';
// $('#results').html(between.join('<br> '));
for(var i=0;i<between.length;i++){
strTopHeadDates=strTopHeadDates+'<th colspan="3">'+between[i]+'</th>';

$('#trBottomHead').append('<th>C</th><th>D</th> <th>E</th>');
$('table>tbody').append('<tr><td>Tiger Nixon</td> <td>System Architect</td> <td>$320,800</td> <td>Edinburgh</td> <td>5421</td> <td>t.nixon@datatables.net</td></tr>');
}
strTopHead=strTopHead+strTopHeadDates;
$('#trTopHead').append(strTopHead);

$('#example').dataTable();
console.log($("#from").val());
}
});

try this code

关于javascript - 通过选择日期选择器创建数据表标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28872066/

26 4 0
文章推荐: ios - Skype Url 在 Objective C 中不起作用?skype ://USER_NAME? 调用(新 Skype 已禁用该功能)
文章推荐: mysql - 在 Rails 中动态创建 mysql 列
文章推荐: MySQL子查询没有给我MAX或ORDER BY LIMIT 1的最高值
文章推荐: javascript - 多个 .on ('click' ... 函数仅绑定(bind)到第一个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com