Home > Article > Web Front-end > Introduction to the method of dynamically setting the checkbox selected state in layui
Today, when using jquery to dynamically set the selected state of the checkbox element of layui, I can only uncheck it, but cannot recheck it. There is no problem if I click to check it. The code is as follows
if (value == "true") { $("#select1").attr("checked", "checked"); } else { $("#select1").removeAttr("checked"); }
Baidu has finally found a usable solution for a long time, using prop instead of attr, as follows:
if (value == "true") { //$id.attr("checked", "checked"); $id.prop("checked", true); } else { $id.prop("checked", false); //$id.removeAttr("checked"); }
For more layui knowledge, please pay attention to the PHP Chinese websitelayui tutorialColumn
The above is the detailed content of Introduction to the method of dynamically setting the checkbox selected state in layui. For more information, please follow other related articles on the PHP Chinese website!