Home >Web Front-end >Layui Tutorial >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} ]
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} ]
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({ ... }); });
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!