-
今天项目有需求 有三个div按钮 点击 前面的input内容要跟着改变 | 昨天 | 前7天 | 前30天
$('body').on('click', '.btn_time div', function () { if ($(this).attr('data-num') == 0) $('.creattime').val(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 ).Format('yyyy-MM-dd hh:mm')); if ($(this).attr('data-num') == 1) $('.creattime').val(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 7).Format('yyyy-MM-dd hh:mm')); if ($(this).attr('data-num') == 2) $('.creattime').val(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 30).Format('yyyy-MM-dd hh:mm')); $(this).siblings().removeClass('btn_active'); $(this).addClass('btn_active'); })
-
HTML
<li class="btn_time"> <div data-num="0">昨天</div> <div data-num="1" class="btn_active">近7天</div> <div data-num="2">近30天</div> </li>
洱月