javascript - daterangepicker how to get value and push 1day to show date on input text
问题描述
I would like to select a date and insert it in the table.
For example, I select a date:
After selecting a date it is inserted in a row as shown:
This is the Javascript code:
$('input[name="allotment"]').on('apply.daterangepicker', function(ev, picker) {
var allomentDate = picker.endDate.format('DD') - picker.startDate.format('DD');
console.log(allomentDate);
console.log(picker);
/* for (i=1;i<=allomentDate;i++){
var dd = start.format('DD').toString();
console.log(dd);
var dateAllot = dd+1;
console.log(dateAllot);
var addRow = "<tr><td><input type='text' name='allomentDate[dateAllot]' readonly value=''></td>" + "<tr><td>";
}*/
});
However it's just getting started. Now, I still can not get value the startdate and enddate.
解决方案
$('input[name="allotment"]').daterangepicker({
"drops": "down",
"opens": "center",
}, function (start, end, label) {
console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
var dd = parseInt(end.format('DD')) - parseInt(start.format('DD'));
var startDate = new Date(start.format('YYYY-MM-DD'));
var endDate = new Date(end.format('YYYY-MM-DD'));
//console.log(startDate.getDate());
//console.log(endDate.getDate());
//console.log(allot);
for (i=1;i<=dd;i++){
var allot = startDate.getDate()+1;
console.log(allot);
var addRow = "<tr><td><input type='text' name='allomentDate[i]' readonly value='startDate'></td>" +
"<tr><td>";
}
});
将 start.format('YYYY-MM-DD') 设置为日期并使用 get.Date + 1
推荐阅读
- keycloak - Keycloak 忘记密码重复电子邮件
- css - 使用 SCSS / CSS 进行目标 Angular 绑定
- flutter - 验证后的登录屏幕应显示新活动(新屏幕)
- oracle - Oracel DB 使用 shell 脚本中的可传输表空间移动巨大的分区
- swift - 何时在 URLSession.shared.dataTask 中使用弱自我
- selenium - 如何使用 TestNG 框架在 Cucumber 上执行并行执行?
- c# - 如何在没有 dotnet 命令行工具的代码中为挂起的迁移生成 SQL 脚本
- pandas - 网页抓取找不到正确的标签
- apache - htacess RewriteRule http://domain/folder/(any searchstring) 重定向到 http://domain/folder/index.php?option=$1
- asynchronous - 如何使用 11.0.0 在 graphql 中禁用异步模式