Home Web Front-end Layui Tutorial Introduction to the use of Form form elements such as Select

Introduction to the use of Form form elements such as Select

Dec 07, 2019 pm 04:43 PM
form 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;//部分表单元素功能才能实现
});
Copy after login

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;
           });
Copy after login

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>
Copy after login
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;);
                   })
Copy after login

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%" }
]]
Copy after login

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%" }
]]
Copy after login

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

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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

What is the reason why Linux uses select? What is the reason why Linux uses select? May 19, 2023 pm 03:07 PM

Because select allows developers to wait for multiple file buffers at the same time, it can reduce IO waiting time and improve the IO efficiency of the process. The select() function is an IO multiplexing function that allows the program to monitor multiple file descriptors and wait for one or more of the monitored file descriptors to become "ready"; the so-called "ready" state is Refers to: the file descriptor is no longer blocked and can be used for certain types of IO operations, including readable, writable, and exceptions. select is a computer function located in the header file #include. This function is used to monitor file descriptor changes—reading, writing, or exceptions. 1. Introduction to the select function. The select function is an IO multiplexing function.

How to use the select syntax of mysql How to use the select syntax of mysql Jun 01, 2023 pm 07:37 PM

1. Keywords in SQL statements are not case-sensitive. SELECT is equivalent to SELECT, and FROM is equivalent to from. 2. To select all columns from the users table, you can use the symbol * to replace the column name. Syntax--this is a comment--query out [all] data from the [table] specified by FEOM. * means [all columns] SELECT*FROM--query out the specified data from the specified [table] from FROM Data of column name (field) SELECT column name FROM table name instance--Note: Use English commas to separate multiple columns selectusername, passwordfrom

Implement Select Channels Go concurrent programming performance optimization through golang Implement Select Channels Go concurrent programming performance optimization through golang Sep 27, 2023 pm 01:09 PM

Implementing SelectChannels through golang Performance optimization of Go concurrent programming In the Go language, it is very common to use goroutine and channel to implement concurrent programming. When dealing with multiple channels, we usually use select statements for multiplexing. However, in the case of large-scale concurrency, using select statements may cause performance degradation. In this article, we will introduce some implementations of select through golang

Select Channels Go concurrent programming for reliability and robustness using golang Select Channels Go concurrent programming for reliability and robustness using golang Sep 28, 2023 pm 05:37 PM

SelectChannels for Reliability and Robustness Using Golang Introduction to Concurrent Programming: In modern software development, concurrency has become a very important topic. Using concurrent programming can make programs more responsive, utilize computing resources more efficiently, and be better able to handle large-scale parallel computing tasks. Golang is a very powerful concurrent programming language. It provides a simple and effective way to implement concurrent programming through go coroutines and channel mechanisms.

BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

See all articles