如何使用日期选择器在javascript中获得ZIG-ZAG格式的日期



我需要在日期选择器中使用日期选择器中的Zig-Zag流,如下模式所示

2014-11-10-2014-11-152014-11-16-2014-11-172014-11-18-2014-11-18

由于您没有指定任何特定的JS库,我假设您指的是HTML5标准<input type="date">,它根据当前使用的浏览器呈现日期选择器。

向用户显示的此日期选择器的格式由用户浏览器的区域设置决定,而使用JavaScript检索的值始终为yyyy-mm-dd格式。

const dateNode = document.querySelector("input[type=date]")
dateNode.addEventListener('change', (event) => {
console.log(`Current JS-Value: ${event.target.value}, which is of type ${typeof event.target.value}`)
})
<label>Enter date:
<input type="date">
</label>

最后我研究了这个解决方案。

function remove(tr_id){         
$("#tr_"+tr_id).remove();    
counter = $("#counter").val();          
counter = parseInt( counter ) - 1 ; 
$("#counter").val(counter);  
}
function AddNewElement(){
counter = $("#counter").val();          
counter = parseInt( counter ) + 1 ; 
// YOUR SPECIFIC DYNAMIC HTML
var elestr = '<tr id="tr_'+counter+'" class="ele_tr"><td><input onclick="remove('+counter+');" id="remove" type="button" value="Remove"></td></tr>';
$("#ele_list").append(elestr);    
$("#counter").val(counter);  
}
$('body').on('focus',".dp_start", function(){
counter = $(this).data('counter');
counter = parseInt(counter);
var trialDate = new Date ($("#enddate_"+ (counter-1)).val());
trialDate.setDate ( trialDate.getDate () + 1 );
$(this).datepicker({
// changeMonth: true, changeYear: true,
dateFormat: "yy-mm-dd",
minDate:  trialDate, 
onClose: function (selectedDate) {
$("#enddate_"+counter).datepicker("option", "minDate", selectedDate);
}
});            
});
$('body').on('focus',".dp_end", function(){
counter = $(this).data('counter');
counter = parseInt(counter);
$(this).datepicker({
// changeMonth: true, changeYear: true,
dateFormat: "yy-mm-dd",
minDate: $("#startdate_"+ (counter)).val(),
onClose: function (selectedDate) {
$("#startdate_"+counter).datepicker("option", "maxDate", selectedDate);
}
});
});

最新更新