When using layui, I encountered a pitfall in the select area. The value in the select could not be cleared. The options in the select had a superposition problem. In order to solve this problem and achieve my function, I did some research and let some Friends who have the same needs don’t step into the trap, so here’s my source code:
<!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>
Related recommendations:
Recommended courses on boundary overlay
Using margin boundary overlay problems and solutions in CSS
The above is the detailed content of The option overlay problem of select in layui. For more information, please follow other related articles on the PHP Chinese website!

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

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

在linux中,option是指命令选项,是调整命令执行行为的开关,即选项不同决定了命令的显示结果不同。option(选项)分为长选项和短选项:1、短选项都是使用“-”引导,当有多个短选项时,各选项之间使用空格隔开;2、长选项都是完整的单词,且通常不能组合。

以下为大家整理了前端UI框架 — layui的视频教程,不需要从迅雷、百度云之类的第三方网盘平台下载,全部在线免费观看。教程由浅入深,有前端基础的人就能学习,从安装到案例讲解,全面详细,帮助你更快更好的掌握layui框架!

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

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

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

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


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

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 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
