Home >Web Front-end >JS Tutorial >Example code of layui table checkbox select all style function

Example code of layui table checkbox select all style function

小云云
小云云Original
2018-03-09 09:23:362654browse

This article mainly shares with you an example of selecting all styles and functions of the layui table checkbox. I hope it can help you. In the previous version, the default check box must have a value. The default check box is "check". It is not suitable for making selections in the form and is difficult to change. Fortunately, after Layui is upgraded, it can support not writing the name value. , to adapt to the selection operation in the table.

1. Layui version number is v1.0.9 rls version (currently the latest version)

<span style="white-space:pre;">	</span><p class="layui-form">
	 <table class="layui-table">
	 <thead>
	  <tr>
	  <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
	  <th>人物</th>
	  <th>民族</th>
	  <th>出场时间</th>
	  <th>格言</th>
	  </tr> 
	 </thead>
	 <tbody>
	  <tr>
	  <td><input type="checkbox" name="" lay-skin="primary"></td>
	  <td>贤心</td>
	  <td>汉族</td>
	  <td>1989-10-14</td>
	  <td>人生似修行</td>
	  </tr>
	  <tr>
	  <td><input type="checkbox" name="" lay-skin="primary"></td>
	  <td>张爱玲</td>
	  <td>汉族</td>
	  <td>1920-09-30</td>
	  <td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
	  </tr>
	 </tbody>
	 </table>
	</p>
	<script type="text/javascript" src="plugins/layui/lay/dest/layui.all.js"></script>
	<script type="text/javascript">
		var $ = layui.jquery,
			form = layui.form();
		//全选
		form.on('checkbox(allChoose)', function(data){
		 var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
		 child.each(function(index, item){
		  item.checked = data.elem.checked;
		 });
		 form.render('checkbox');
		});
	</script>

2. Version number is v1.0.9 rls and previous versions need to update several files

(a) layui.all.js file in layui\lay\dest

(b) form.js file in layui\lay\modules

(c) The layui.css file in layui\css

Overwrite the above three files from the latest version to the original version, and you can easily implement the checkbox style.

Related recommendations:

JS implementation of checkBox’s radio selection effect example code

The two columns of CheckBox in the table can only be selected A jQuery code

How to beautify the style of HTML checkbox and radio

The above is the detailed content of Example code of layui table checkbox select all style function. 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