layui dynamic setting checbox selected

layui checkbox checkbox checked assignment, solve layui setting does not take effect checbox selected issues

Directly on the code

//监听指定开关
form.on('switch(dongsir)', function(data){
    $("input[type=checkbox]").prop('checked',this.checked);
    form.render('checkbox');
});

Directly attr = checked is invalid

For prop and attr online have some different ideas, here compiled some your reference:

For the inherent attributes of the HTML element itself with, when handling, using prop method;
for our own custom HTML element's DOM properties during handling, use attr method;

We want to operate in some of the labels are elements inherent attributes, recommended prop, referring to the inherent properties of the label itself has a number of attributes, such as the href attribute of a tag, src attribute of the img tag;
and we want to operate since some of the properties is defined, it recommended attr;

Guess you like

Origin www.cnblogs.com/sirdong/p/11774882.html