layui监听select,监听switch
注意:lay-filter=" "这个属性,以及class="layui-form"这个属性
监听select
<span class="layui-form">
<select lay-filter="add_product_gid" class="layui-select" name="add_product_gid" id="add_product_gid">
<option value="" >-请选择-</option>
<option value="1" data-id="123" >1</option>
</select>
<span>
form.on('select(add_product_gid)', function(data){
var data_val = data.value;//值
var id = data.elem.attributes['data-id'].nodeValue;//获取其他属性值
});
监听switch
<span class="layui-form">
{eq name='vo.is_hot' value='0'}
<input type="checkbox" lay-filter="is_hot_status" name="switch" id="is_hot_status" lay-skin="switch" lay-text="是|否" data-id="{$vo.id}" value="{$vo.is_hot}">
{else}
<input type="checkbox" lay-filter="is_hot_status" name="switch" id="is_hot_status" lay-skin="switch" lay-text="是|否" data-id="{$vo.id}" checked value="{$vo.is_hot}">
{/eq}
</span>
form.on('switch(is_discount_status)',function (data) {
//开关是否开启,true或者false
var checked = data.elem.checked;
var id = data.elem.attributes['data-id'].nodeValue;
//TODO 此时进行ajax的服务器访问,如果返回数据正常,则进行后面代码的调用
//是否打折,0否,1是
var is_discount = 0;
if(checked === true){
is_discount = 1;
}
form.render();
});