Introduction to the method of dynamically setting the checkbox selected state in layui

Release: 2020-06-20 16:12:34
forward
6714 people have browsed it

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"); }
Copy after login

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"); }
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!