Javascript 选择当前月份
我有一个复选框,上面有我要检查当前月份的月份值 var d=新日期, n=d.getMonth, y=d.getFullYear; console.logn; $input[name='month[]']。每个函数{ $this.val.split; console.log$this.val.split-[0]; }; 2020年4月-2020年 2020年5月 2020年6月 您可以将复选框的ID更新为一个月的匹配索引,并执行以下操作: const date=新日期; const monthIndex=date.getMonth; const year=date.getFullYear; $`${monthIndex}`.propchecked,true; 2020年4月-2020年 2020年5月 2020年6月 您可以将复选框的ID更新为一个月的匹配索引,并执行以下操作: const date=新日期; const monthIndex=date.getMonth; const year=date.getFullYear; $`${monthIndex}`.propchecked,true; 2020年4月-2020年 2020年5月 2020年6月Javascript 选择当前月份,javascript,html,jquery,Javascript,Html,Jquery,我有一个复选框,上面有我要检查当前月份的月份值 var d=新日期, n=d.getMonth, y=d.getFullYear; console.logn; $input[name='month[]']。每个函数{ $this.val.split; console.log$this.val.split-[0]; }; 2020年4月-2020年 2020年5月 2020年6月 您可以将复选框的ID更新为一个月的匹配索引,并执行以下操作: const date=新日期; const mont
您可以将当前值与您的值进行比较,并将选中设置为
if(month == currentMonth){
$(this).attr('checked', 'checked')
}
var d=新日期,
n=d.getMonth,
y=d.getFullYear;
console.logn;
$input[name='month[]']。每个函数{
$this.val.split;
var month=$this.val.split-[0];
var currentMonth=getMonthnew日期;
//每月一次;
ifmonth==currentMonth{
$this.attr'checked','checked'
}
};
函数getMonthd{
var月=新数组;
月[0]=一月;
月[1]=二月;
月[2]=三月;
月[3]=四月;
月[4]=五月;
月[5]=六月;
月[6]=7月;
月[7]=8月;
月[8]=九月;
月[9]=10月;
月[10]=11月;
月[11]=12月;
返回月[d.getMonth];
}
2020年4月-2020年
2020年5月
2020年6月
您可以将当前值与您的值进行比较,并将选中设置为
if(month == currentMonth){
$(this).attr('checked', 'checked')
}
var d=新日期,
n=d.getMonth,
y=d.getFullYear;
console.logn;
$input[name='month[]']。每个函数{
$this.val.split;
var month=$this.val.split-[0];
var currentMonth=getMonthnew日期;
//每月一次;
ifmonth==currentMonth{
$this.attr'checked','checked'
}
};
函数getMonthd{
var月=新数组;
月[0]=一月;
月[1]=二月;
月[2]=三月;
月[3]=四月;
月[4]=五月;
月[5]=六月;
月[6]=7月;
月[7]=8月;
月[8]=九月;
月[9]=10月;
月[10]=11月;
月[11]=12月;
返回月[d.getMonth];
}
2020年4月-2020年
2020年5月
2020年6月
这应该行得通
var d=新日期,
n=d.getMonth,
y=d.getFullYear;
var月=新数组;
月[0]=一月;
月[1]=二月;
月[2]=三月;
月[3]=四月;
月[4]=五月;
月[5]=六月;
月[6]=7月;
月[7]=8月;
月[8]=九月;
月[9]=10月;
月[10]=11月;
月[11]=12月;
var currentDate=月份[n]+'-'+y;
$input[name='month[]']。每个函数{
$this.val.split;
console.log$this.val.split-[0];
};
$`input[type=checkbox][value=${currentDate}]`.prop'checked',true;
2020年4月-2020年
2020年5月
2020年6月
这应该行得通
var d=新日期,
n=d.getMonth,
y=d.getFullYear;
var月=新数组;
月[0]=一月;
月[1]=二月;
月[2]=三月;
月[3]=四月;
月[4]=五月;
月[5]=六月;
月[6]=7月;
月[7]=8月;
月[8]=九月;
月[9]=10月;
月[10]=11月;
月[11]=12月;
var currentDate=月份[n]+'-'+y;
$input[name='month[]']。每个函数{
$this.val.split;
console.log$this.val.split-[0];
};
$`input[type=checkbox][value=${currentDate}]`.prop'checked',true;
2020年4月-2020年
2020年5月
2020年6月
您需要将月份索引映射到它们的名称,然后根据其索引很容易识别上个月: const monthsNames=[‘一月’、‘二月’、‘比赛’、‘四月’、‘五月’、‘六月’、‘七月’、‘八月’、‘九月’、‘十月’、‘十一月’、‘十二月’]; var d=新日期, n=d.getMonth, y=d.getFullYear; const previousMonthName=monthnames[n-1]; $input[name='month[]']。每个函数{ const monthName=$this.val.split-[0]; 如果monthName==上一个monthName{ $this.attr'checked','checked'; } }; 2020年4月-2020年 2020年5月 2020年6月
您需要将月份索引映射到它们的名称,然后根据其索引很容易识别上个月: const monthsNames=[‘一月’、‘二月’、‘比赛’、‘四月’、‘五月’、‘六月’、‘七月’、‘八月’、‘九月’、‘十月’、‘十一月’、‘十二月’]; var d=新日期, n=d.getMonth, y=d.getFullYear; const previousMonthName=monthnames[n-1]; $input[name='month[]']。每个函数{ const monthName=$this.val.split-[0]; 如果monthName==上一个monthName{ $this.attr'checked','checked'; } }; 2020年4月-2020年 2020年5月 2020年6月
找到当前日期,然后使用ECMAScript国际API设置上个月的新日期,下个月的名称 然后检查哪个月是最近的月份
var d = new Date(),
newDate = new Date(d.setMonth(d.getMonth() - 1)),
lastMonth = newDate.toLocaleString('default', { month: 'long' });
$("input[name='month[]']").on('change', function()
{
$(this).filter(':checked').each(function(){
$(this).val().split("_")[0];
console.log($(this).val().split("-")[0]);
if ($(this).val().split("-")[0] == lastMonth )
{
console.log(`${$(this).val().split("-")[0]} is the last month`);
}
});
});
找到当前日期,然后使用ECMAScript国际API设置上个月的新日期,下个月的名称 然后检查哪个月是最近的月份
var d = new Date(),
newDate = new Date(d.setMonth(d.getMonth() - 1)),
lastMonth = newDate.toLocaleString('default', { month: 'long' });
$("input[name='month[]']").on('change', function()
{
$(this).filter(':checked').each(function(){
$(this).val().split("_")[0];
console.log($(this).val().split("-")[0]);
if ($(this).val().split("-")[0] == lastMonth )
{
console.log(`${$(this).val().split("-")[0]} is the last month`);
}
});
});
你有什么问题?我有一个月的电话号码也许你应该
将id设置为复选框,如:何时是四月,类似于id=month_3 3,因为我认为Date给出的数字介于0-11之间,那么您可以将实际月份与id month_u+实际月份进行比较这是一个动态过滤器您需要创建一个数组/对象,将月份名称映射到其索引,那么你的问题是什么呢?我有一个月的数字可能你应该把id改成checboxe,比如:什么时候是四月,比如id=month\u 3 3,因为我认为Date给出的数字在0-11之间,那么你可以将实际月份与id month\u+actualmonth进行比较这是一个动态过滤器你需要创建一个映射的数组/对象这些月的名字都是他们的索引,那么这就无关紧要了