Home > Web Front-end > Layui Tutorial > How to set checkbox in layui

How to set checkbox in layui

爱喝马黛茶的安东尼
Release: 2019-07-11 10:27:34
Original
13503 people have browsed it

How to set checkbox in layui

Method 1

Set LAY_CHECKED to true in the returned json, and the checkbox on the page is selected. .

data":[
    {"name":"北京市","areaType":"省/直辖市","id":"110000","LAY_CHECKED":true},
    {"name":"市辖区","areaType":"地市","id":"110100","LAY_CHECKED":true},
    {"name":"县","areaType":"地市","id":"110200","LAY_CHECKED":false}
]
Copy after login

Related recommendations: "layui Framework Tutorial"

Method 2

What to do if there is no LAY_CHECKED in the returned data ? For example, the following data is returned:

data":[
    {"name":"北京市","areaType":"省/直辖市","id":"110000","checked":true},
    {"name":"市辖区","areaType":"地市","id":"110100","checked":true},
    {"name":"县","areaType":"地市","id":"110200","checked":false}
]
Copy after login

Note: checked is used here to identify whether it is selected, not LAY_CHECKED.

At this time, you can modify the js of the page.

layui.use('table', function(){    
    var $ = layui.$;    
    var table = layui.table;    
   //在使用table之前加上下面这句就可以了
   table =  $.extend(table, {config: {checkName: 'checked'}});
   table.render({
       ...
   });
});
Copy after login

The above is the detailed content of How to set checkbox in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template