How to deal with select option overlay
This time I will show you how to deal with the option overlay of select. What are the precautions when dealing with the option overlay of select? The following is a practical case, let's take a look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>layui-下拉框联动测试</title> <link rel="stylesheet" href="layui/css/layui.css" rel="external nofollow" > </head> <body> <p id="wrap"> <p class="layui-form" lay-filter="merchantForm"> <p class="layui-form-item"> <label class="layui-form-label">选择框</label> <p class="layui-input-block"> <select name="city" lay-verify="required" id="test1" lay-filter="test1"> <option value="0">时间</option> <option value="1">金额</option> </select> </p> </p> <p class="layui-form-item"> <label class="layui-form-label">选择框</label> <p class="layui-input-block"> <select name="city" lay-verify="required" id="test2" lay-filter="test2"> <option value="">请选择规则名称</option> </select> </p> </p> </p> <button id="btn">确定</button> </body> <script src="layui/layui.all.js"></script> <script src="layui/jquery-1.8.3.min.js"></script> <script> //后台传过来的数据 var data=[ {unitType:0,ruleName:'时间规则11',amount:1100,money:1100}, {unitType:0,ruleName:'时间规则12',amount:1200,money:1200}, {unitType:0,ruleName:'时间规则13',amount:1300,money:1300}, {unitType:1,ruleName:'金额规则21',amount:2100,money:2100}, {unitType:1,ruleName:'金额规则22',amount:2200,money:2200}, {unitType:1,ruleName:'金额规则23',amount:2300,money:2300}, ]; //初始化默认为时间类型以及对应的时间规则 layui.use('form', function(){ var form = layui.form; $('#test2').html(''); var html=''; $.each(data,function(i,e){ if(e.unitType==0) html+=`<option data-type="${e.unitType}">${e.ruleName}</option>`; }) $('#test2').append(html); form.render('select'); }) //动态二级联动 layui.use('form', function(){ var form = layui.form; form.on('select(test1)', function(obj){ $('#test2').html(''); var html=''; if(obj.value==0){ $.each(data,function(i,e){ if(e.unitType==obj.value) html+=`<option data-type="${e.unitType}">${e.ruleName}</option>`; }) $('#test2').append(html); }else if(obj.value==1){ $.each(data,function(i,e){ if(e.unitType==obj.value) html+=`<option data-type="${e.unitType}">${e.ruleName}</option>`; }) $('#test2').append(html); } form.render('select'); }); }) //二级联动完毕后获取对应的规则数据 $('#btn').click(function(){ var thisValue=data.find((v)=>v.ruleName==$('#test2').val()); console.log(thisValue); }) </script> </html>
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 to import css library in vue.js
Installation method of vue and element components
The above is the detailed content of How to deal with select option overlay. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

Quickly learn how to open and process CSV format files. With the continuous development of data analysis and processing, CSV format has become one of the widely used file formats. A CSV file is a simple and easy-to-read text file with different data fields separated by commas. Whether in academic research, business analysis or data processing, we often encounter situations where we need to open and process CSV files. The following guide will show you how to quickly learn to open and process CSV format files. Step 1: Understand the CSV file format First,

How to handle XML and JSON data formats in C# development requires specific code examples. In modern software development, XML and JSON are two widely used data formats. XML (Extensible Markup Language) is a markup language used to store and transmit data, while JSON (JavaScript Object Notation) is a lightweight data exchange format. In C# development, we often need to process and operate XML and JSON data. This article will focus on how to use C# to process these two data formats, and attach

In the process of PHP development, dealing with special characters is a common problem, especially in string processing, special characters are often escaped. Among them, converting special characters into single quotes is a relatively common requirement, because in PHP, single quotes are a common way to wrap strings. In this article, we will explain how to handle special character conversion single quotes in PHP and provide specific code examples. In PHP, special characters include but are not limited to single quotes ('), double quotes ("), backslash (), etc. In strings

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

Generators in PHP7: How to handle large-scale data efficiently and save memory? Overview: PHP7 introduces generators as a powerful tool in terms of large-scale data processing and memory saving. Generators are a special type of function in the PHP language. Unlike ordinary functions, generators can pause execution and return intermediate results instead of returning all results at once. This makes the generator ideal for processing large batches of data, reducing memory usage and improving processing efficiency. This article will introduce students

How to deal with multi-language and internationalization issues in PHP development requires specific code examples. With the development of the Internet, people's demand for multi-language and internationalization is getting higher and higher. In PHP development, how to effectively handle multi-language and internationalization issues has become an important task that developers need to solve. Handling of character encoding In PHP development, we must first ensure that character encoding is handled correctly. In multi-language environments, using UTF-8 encoding is the most common choice. You can add the following code to the head of the PHP file: header('C

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:
