写个获取今天日期的方法,然后给两个input分别赋值就行了
function getNow(s) {
return s < 10 ? '0' + s : s;
}
function nowData() {
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var date = myDate.getDate();
begindate = year + '-' + getNow(month) + "-" + getNow(date) + " " + '00:00:00';
enddate = year + '-' + getNow(month) + "-" + getNow(date) + " " + '23:59:59';
//插件的两个输入框赋值
$('.control .c-datepicker-date-editor .now').val(begindate);
$('.control .c-datepicker-date-editor .nowlast').val(enddate);
}
$('.J-datepicker-day').datePicker({
hasShortcut: true,
format: 'YYYY-MM-DD'
});单个的年月日一个页面出现了多个 我复制的都是一样的 如何获得每个选中的日期
第一种,在回调里获取:
$('.J-datepicker-day').datePicker({
format: 'YYYY-MM-DD',
hide: function(type) {
// 可以在调用的html加个data-index='1'或加类名去区分是哪个
console.info(this.$input.parents('.J-datepicker-day').index().data('index'))
console.info(this.$input.eq(0).val());
console.info('类型:', type)
}
});第二种:普通jquery去获取
// 单个直接获取,范围组件遍历获得的元素去获取val
$('.J-datepicker-day').eq(0).find('input').val()
附上简单的修改
// 设置日期选择框位置
function setContainerPos(_this) {
var w = document.documentElement.clientWidth;
var new_w = _this.$target.offset().left + _this.$target.width() + 60;
var offset = _this.$target.offset();
var height = _this.$target.outerHeight();
if (w > new_w) {
_this.pickerObject.$container.css({
top: offset.top + height,
left: offset.left
});
} else {
_this.pickerObject.$container.css({
top: offset.top + height,
right: 60
});
}
}