因为本身layui是有一套自身的监听方式,form.on 当然你是先将select放入<div class="layui-form">中,不然都显示不出select
里面也有监听普通下拉选框选中值发生改变的方式,直接复制即可
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>监听下拉选框</title> <link rel="stylesheet" href="//layui.hcwl520.com.cn/layui/css/layui.css?v=201809030202" rel="external nofollow" > </head> <body> <div class="layui-form"> <div class="layui-inline"> <div class="layui-inline"> <label class="layui-form-label">layui监听下拉选框</label> <div class="layui-input-inline layui-input-inline-add"> <select id="Select" lay-filter="Select" name="aaa" lay-search=""> <option value="0">1</option> <option value="1">2</option> <option value="2">3</option> </select> </div> </div> </div> </div> <h3 style="margin-top: 50px;">普通监听下拉选框</h3> <select name="" id="common" style="height: 35px;width: 200px;margin-left:110px;"> <option value="0">1</option> <option value="1">2</option> <option value="2">3</option> </select> <script src="http://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> <script src="//layui.hcwl520.com.cn/layui/layui.js?v=201809030202"></script> <script> layui.use(['form','layer'],function () { var form=layui.form; var layer=layui.layer; form.on('select(Select)',function(data){ layer.msg('监听到下拉选框选中值发生改变') }); }) $("#common").on('change',function () { alert('监听到下拉选框选中值发生改变') }) </script> </body> </html>
以上这篇layui监听下拉选框选中值变化的方法(包含监听普通下拉选框)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。