layui 表单监听 radio
2020-05-22 本文已影响0人
焰火青春
1、html
<div class="layui-inline">
<label class="layui-form-label">过期时间</label>
<div class="layui-input-block">
<input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
autocomplete="off" class="layui-input">
</div>
<div class="layui-input-block">
<input type="radio" name="expire_time" lay-filter="expire_time" num="1" value="1个月"
title="1个月">
<input type="radio" name="expire_time" lay-filter="expire_time" num="3" value="3个月"
title="3个月" checked>
<input type="radio" name="expire_time" lay-filter="expire_time" num="6" value="半年"
title="半年" checked>
</div>
</div>
2、js
// 监听单选框:过期时间
form.on('radio(expire_time)', function (data) {
var now_timer = new Date();
var num = $(data.elem).attr('num');
now_timer.setMonth(now_timer.getMonth() + parseInt(num));
var change_time = '' + now_timer.getFullYear() + '-' + (now_timer.getMonth() + 1) + '-' + now_timer.getDate() + '';
$('#date').val(change_time);
});
注意:需要指定
lay-filter