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

How to set checkbox in layui

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-11 10:27:1313460browse

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!

Statement:
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