Home > Web Front-end > JS Tutorial > body text

Use checkbox to operate layui tables

php中世界最好的语言
Release: 2018-03-28 15:08:39
Original
3370 people have browsed it

This time I will bring you the use of checkbox to operate layui tables, and what are the precautions for using checkbox to operate layui tables. The following is a practical case, let's take a look.

In the previous version, the default

checkbox must have a value. The default is the word "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>
Copy after login

2. Version Versions before v1.0.9 rls need to update several files

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

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

modules

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

Change the above three files from the latest By overwriting the original version in the version, you can easily implement the checkbox style.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How $set updates the array in vue.js

How does JQuery select the value specified in the select component

The above is the detailed content of Use checkbox to operate layui tables. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!