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
How do I use Layui's flow module for infinite scrolling?How do I use Layui's flow module for infinite scrolling?Mar 18, 2025 pm 01:01 PM

The article discusses using Layui's flow module for infinite scrolling, covering setup, best practices, performance optimization, and customization for enhanced user experience.

How do I use Layui's element module to create tabs, accordions, and progress bars?How do I use Layui's element module to create tabs, accordions, and progress bars?Mar 18, 2025 pm 01:00 PM

The article details how to use Layui's element module to create and customize UI elements like tabs, accordions, and progress bars, highlighting HTML structures, initialization, and common pitfalls to avoid.Character count: 159

How do I customize the appearance and behavior of Layui's carousel module?How do I customize the appearance and behavior of Layui's carousel module?Mar 18, 2025 pm 12:59 PM

The article discusses customizing Layui's carousel module, focusing on CSS and JavaScript modifications for appearance and behavior, including transition effects, autoplay settings, and adding custom navigation controls.

How do I use Layui's carousel module to create image sliders?How do I use Layui's carousel module to create image sliders?Mar 18, 2025 pm 12:58 PM

The article guides on using Layui's carousel module for image sliders, detailing steps for setup, customization options, implementing autoplay and navigation, and performance optimization strategies.

How do I configure Layui's upload module to restrict file types and sizes?How do I configure Layui's upload module to restrict file types and sizes?Mar 18, 2025 pm 12:57 PM

The article discusses configuring Layui's upload module to restrict file types and sizes using accept, exts, and size properties, and customizing error messages for violations.

How do I use Layui's layer module to create modal windows and dialog boxes?How do I use Layui's layer module to create modal windows and dialog boxes?Mar 18, 2025 pm 12:46 PM

The article explains how to use Layui's layer module to create modal windows and dialog boxes, detailing setup, types, customization, and common pitfalls to avoid.

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

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.