search
HomeWeb Front-endLayui TutorialIntroduction to the use of Form form elements such as Select

Introduction to the use of Form form elements such as Select

Regarding Form elements such as Select, some features will become invalid when used.

For example, the Search function that comes with select:

Introduction to the use of Form form elements such as Select

In fact, when using the Form form element, if you need some of the functions that come with layui (search, verification, etc.), please enclose it with

tags and need to be initialized. form object, so that rendering can take effect. Similarly, tabs need to initialize the element object
//注意:选项卡 依赖 element 模块,否则无法进行功能性操作
layui.config({
    base: '/Resources/Script/'
})
.use(['element', 'common', 'form'], function () {
    var element = layui.element;//tab选项卡类的功能才能实现
    var form = layui.form;//部分表单元素功能才能实现
});

About the automatic submission event of the cancel button

layui will automatically submit the form when using the button, no matter you The button type is not submit.

Solution:

1. As long as you put it inside the

tag, it will be automatically submitted. For general use, please put it outside the Form.

2. The return value of the button click event must return false, and form submission can also be organized.

Note that there is a small detail here, that is, the form elements enclosed by the Form form. You can use Jquery's Seriliaze method to quickly encapsulate the form result set: (I encapsulate a JSON object)

var formData = $("#infoForm").serializeArray();
           var data = {};
           $.each(formData, function (index, item) {
               data[item.name] = item.value;
           });

Or generate a string with key=value&key1=value2 (using Serialize())

But if you get the select option of the layui form here, it will hide your original select and re-render it. A select. At this time, you cannot get the value of the select through the above method. You can still use $().value. The option of the default option must be assigned value='', otherwise when the value is rendered, the text() value will be copied by default. .

Introduction to the use of Form form elements such as Select

The default value initialization of laydate:

Introduction to the use of Form form elements such as Select

Please turn on isInitValue, personally think the document writes It's not accurate, and it feels like a useless configuration. Anyway, isInitValue must be explicitly pointed out before the default value can be initialized.

About the asynchronous loading parameters of the DataTable data table:

Introduction to the use of Form form elements such as Select

Regarding request, when making a layui request, the parameters include pageIndex and pageSize by default. You can pass the request parameter Go configure your own pageIndex and pageSize names. Additional request parameters need to be encapsulated into where, and finally layui will assemble them together and send them to the background.

Introduction to the use of Form form elements such as Select

Introduction to the use of Form form elements such as Select

Regarding the response parameter configuration, four items must be pointed out when drawing lines. You can transfer other parameters in the background at will and get them when done.

About province and city linkage (local rendering at the control level)

Because layui does not have the concept of two-way binding, what is done here can only be repeated each time Get the data, then render and refresh the control. Therefore, what is generally adopted is the partial rendering of the form listening event through: form -form and lay-filter attributes) enclose the select, and then perform form.select('select', the div containing the select: filter attribute value), so that you do not need to refresh all form selects, but render a certain select , but event monitoring can go to the control level (that is, the lay-filter is marked on the control).

<div class="layui-form" lay-filter="selLocation">
                            <label class="text_label">出发站:</label>
                            <div class="layui-input-inline">
                                <select id="selLocation" name="selLocation" class="text_input" lay-filter="selLocation" lay-verify="" lay-search></select>
                            </div>
                        </div>
form.on("select(selLine)", function (data) {
                       var template1 = "<option value=&#39;&#39;>全部选项</option>";
                       for (var index in result.Data) {
                           if (result.Data[index].LineId == data.value) {
                               template1 += "<option value=&#39;" + result.Data[index].TimesId + "&#39;>" + result.Data[index].TimesName + "</option>";
                           }
                       }
                       $("#selTimes").html(template1);
                       form.render(&#39;select&#39;,&#39;selLlocation&#39;);
                   })

Implementation of self-increasing columns of data list (two types)

1. Use the template engine

模板:
<script type="text/html" id="indexTpl">
    {{d.LAY_TABLE_INDEX+1}}
</script>
table的col参数:
cols: [[
            { title: &#39;序号&#39;, templet: &#39;#indexTpl&#39;, width: "6%" }
]]

2. Use the parameters in col type:numbers (note that this parameter is new in layui2.2.0)

cols: [[
            { title: &#39;序号&#39;, type:&#39;numbers&#39;, width: "6%" }
]]

I recommend the second method. The second method is sorting with paging. The second page is an index that increases from the previous page, and The serial number will not change during sorting. In the first type, during sorting, the serial number will change from 10-1

Introduction to the use of Form form elements such as Select. Finally, as for how the back-end staff writes the front-end code, it is slightly visible. Some suggestions for the pages (most of them are forms)

My suggestions are:

Introduction to the use of Form form elements such as Select1. First understand the grid layout and some basic frameworks that are easy to use. All have layouts.

2. Use chrome to modify the element style, then cp the modified style yourself, and then encapsulate it into a css.

3. When using components, carefully look at the structure and don’t Destroying the original structure can easily lead to failure.

4. Don’t copy the demo completely, because the demos still have a big impact, that is, the elements are nested before, so be sure to read the rules clearly. For our backend staff, knowing these few points is almost enough, and we can already handle most applications.

For more layui knowledge, please pay attention to the layui usage tutorial column.

The above is the detailed content of Introduction to the use of Form form elements such as Select. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
使用golang进行Select Channels Go并发式编程的异步处理方法使用golang进行Select Channels Go并发式编程的异步处理方法Sep 28, 2023 pm 05:27 PM

使用golang进行SelectChannelsGo并发式编程的异步处理方法引言:并发式编程是现代软件开发中的一个重要领域,它可以有效地提高应用程序的性能和响应能力。在Go语言中,使用Channels和Select语句可以简单而高效地实现并发编程。本文将介绍如何使用golang进行SelectChannelsGo并发式编程的异步处理方法,并提供具体的

jquery如何隐藏select元素jquery如何隐藏select元素Aug 15, 2023 pm 01:56 PM

jquery隐藏select元素的方法:1、hide()方法,在HTML页面中引入jQuery库,可以使用不同选择器来隐藏select元素,ID选择器将selectId替换为你实际使用的select元素的ID;2、css()方法,使用ID选择器选择需要隐藏的select元素,使用css()方法将display属性设置为none,并将selectId替换为select元素的ID。

jQuery中如何实现select元素的改变事件绑定jQuery中如何实现select元素的改变事件绑定Feb 23, 2024 pm 01:12 PM

jQuery是一个流行的JavaScript库,可以用来简化DOM操作、事件处理、动画效果等。在web开发中,经常会遇到需要对select元素进行改变事件绑定的情况。本文将介绍如何使用jQuery实现对select元素改变事件的绑定,并提供具体的代码示例。首先,我们需要使用标签来创建一个包含选项的下拉菜单:

linux要用select的原因是什么linux要用select的原因是什么May 19, 2023 pm 03:07 PM

因为select可以使开发者在同时等待多个文件缓冲区,可减少IO等待的时间,能够提高进程的IO效率。select()函数是IO多路复用的函数,允许程序监视多个文件描述符,等待所监视的一个或者多个文件描述符变为“准备好”的状态;所谓的”准备好“状态是指:文件描述符不再是阻塞状态,可以用于某类IO操作了,包括可读,可写,发生异常三种。select是一个计算机函数,位于头文件#include。该函数用于监视文件描述符的变化情况——读写或是异常。1.select函数介绍select函数是IO多路复用的函

mysql的select语法怎么使用mysql的select语法怎么使用Jun 01, 2023 pm 07:37 PM

1、SQL语句中的关键词对大小写不敏感,SELECT等效于SELECT,FROM等效于from。2、从users表中选择所有列的,可以用符号*代替列的名称。语法--这是注释--从FEOM指定的[表中],查询出[所有的]数据.*表示[所有列]SELECT*FROM--通过从FROM从指定的[表中],查询出指定列名称(字段)的数据SELECT列名称FROM表名称实例--注意:多个列之间,使用英文的逗号来分隔selectusername,passwordfrom

BinaryX再次更名FORM,还给社区的FOUR即将暴涨?BinaryX再次更名FORM,还给社区的FOUR即将暴涨?Mar 04, 2025 pm 12:00 PM

BinaryX的代币更名:从BNX到FOUR,再到FORM,战略调整背后的深层含义BinaryX近期将代币符号从$FOUR更改为$FORM,引发业界广泛关注。这并非BinaryX首次更名,其代币符号曾经历BNX到FOUR的转变。本文将深入探讨这一系列更名背后的战略意图。一、代币更名历程与战略考量BinaryX最初于2021年推出基于BNB链的$BNX代币,用于支持其Play-to-Earn(P2E)游戏生态。2024年初,为优化经济模型,BinaryX对$BNX进行了分割,并逐渐拓展至GameF

通过golang实现Select Channels Go并发式编程的性能优化通过golang实现Select Channels Go并发式编程的性能优化Sep 27, 2023 pm 01:09 PM

通过golang实现SelectChannelsGo并发式编程的性能优化在Go语言中,使用goroutine和channel实现并发编程是非常常见的。而在处理多个channel的情况下,我们通常会使用select语句来进行多路复用。但是,在大规模并发的情况下,使用select语句可能会导致性能下降。在本文中,我们将介绍一些通过golang实现select

使用golang实现可靠性和鲁棒性的Select Channels Go并发式编程使用golang实现可靠性和鲁棒性的Select Channels Go并发式编程Sep 28, 2023 pm 05:37 PM

使用Golang实现可靠性和鲁棒性的SelectChannelsGo并发式编程引言:在现代软件开发中,并发性已经成为了一个非常重要的主题。使用并发编程可以使得程序更具有响应性、更高效地利用计算资源,并且能够更好地处理大规模的并行计算任务。Golang是一种非常强大的并发编程语言,它通过go协程和channel机制,提供了一种简单而有效的方式来实现并发编程

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools