search
HomeWeb Front-endLayui TutorialHow to set select items in layui

The method of setting the select item in layui: first create an HTML sample file; then request the select elements from the background through ajax; finally, click on a certain dd element under dl to realize the select selection Events are enough.

How to set select items in layui

The operating environment of this tutorial: Windows 7 system, layui version 1.0. This method is suitable for all brands of computers.

Recommended: "javascript basic tutorial""layUI tutorial"

1. Demand scenario analysis

The user needs to change something Information about an activity. The activity information contains field A that needs to be selected using the drop-down box. When the user clicks to modify the pop-up dialog box, the existing activity information needs to be filled in, and the existing value of field A is automatically selected.

2. How to implement Layui's select drop-down box

In order to obtain a select drop-down box that comes standard, we need to fill in the content in the html as follows:

<div class="layui-form-item">
 <label class="layui-form-label"><span class="color-red">* </span>发送对象:</label>
 <div class="layui-input-inline">
  <select id="edit_exam_school">
   <option value="">请选择</option>
   <option value="1">华南理工大学大学城</option>
   <option value="2">华南理工大学五山校区</option>
   <option value="3">中山大学珠海校区</option>
   <option value="4">中山大学大学城校区</option>
  </select>
 </div>
</div>

What is the rendering result of layui on the above html?

How to set select items in layui

The elements available for selection here are obtained from the background request through ajax, and which one to select needs to be decided based on the dynamic results. Analyze the structure of the rendering result and get the dom tree as follows:

How to set select items in layui

#It is found that in addition to select under layui-input-inline, there is another layui-form-select. div. This div contains two child elements, layui-select-title and dl. The select event of select can be achieved by clicking on a certain dd element under dl.

3. How to implement automatic selection?

From the above analysis results, we can know that as long as we get the dd element where the content we want to select is located and trigger a click event on it, we can realize the automatic selection operation when the select is loaded.

First you need to use lay-value to determine which element needs to be set for automatic selection

var select = &#39;dd[lay-value=&#39; + data.schoolId + &#39;]&#39;;

Trigger the click event to achieve automatic selection

$(&#39;#edit_exam_school&#39;).siblings("div.layui-form-select").find(&#39;dl&#39;).find(select).click();

The above is the detailed content of How to set select items in layui. 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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

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

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.