layui监听单选框radio改变事件

  • A+
所属分类:JQuery/Js 技术杂谈

一般情况下的radio的监听事件可以这么写:

$(document).ready(function() {
    $('input[type=radio][name=together_send]').change(function() {
        alert(this.value);
    });
});

但是我在使用的layui组件radio的时候,这种写法就会失去效果,我们就得使用layui组件的监听写法,例子如下:

label class="layui-form-label">是否合发</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="together_send" value="0" lay-filter="together_send" title="否" checked>
                            <input type="radio" name="together_send" value="1" lay-filter="together_send" title="是">
                        </div>

在radio中加入 lay-filter 属性

// radio监听事件
    form.on("radio(together_send)", function (data) {
       var val = data.value;
      alert(val);
    });

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: