search
HomeWeb Front-endLayui TutorialLayui's method of listening to multiple radio events

Layui's method of listening to multiple radio events

The requirements are as follows: If you want to select radio button 3, select all the check boxes under radio button 3

Layuis method of listening to multiple radio events

If there is not much information in the panel, you can add a fixed listening event to each radio button 3

But in the actual project, there are not only two, but dozens. At this time, you can never bind Define a lay-filter and add a form.on('radio(filter)') event

So here I wrote a general method for monitoring multiple radios:

// 选取“单选框3”,“单选框3”下的所有内容全选
        var flagID = document.querySelectorAll("input[title='单选框3']");
        var aFlagID = new Array();
        for (var j = 0; j < flagID.length; j++) {
            aFlagID.push(flagID[j].id);
        }
        // 监听所有title为“单选框3”的radio
        // 注意:此时title为“单选框3”的radio的id和lay-filter需要设为一致!!!!
        for (var i = 0; i < aFlagID.length; i++) {
             form.on(&#39;radio(&#39;+aFlagID[i]+&#39;)&#39;, function(data) {
                $(data.elem).next().next().children("input").addClass(""+aFlagID[i]+"_other");
                $("."+aFlagID[i]+"_other").attr("checked", "checked");
                $("."+aFlagID[i]+"_other + div").addClass(&#39;layui-form-checked&#39;);
                element.init();
            });
        }

This Here, the lay-filter of each radio is obtained through the id, and the radio id and lay-filter are set to be the same;

$(data.elem) is the currently monitored DOM element; please note here Look at the page that has been successfully rendered by the browser;

The input element is selected at this time, which is radio button 3, but because layui beautifies the input, the input is not displayed;

Layuis method of listening to multiple radio eventsPay attention to the picture below: at this time, the next element of input is the "radio button 3" we see

Layuis method of listening to multiple radio events

Be sure to look for it when selecting the element Quasi-element!

This method has the following limitations:

1. You need to manually set the id and lay-filter for each "radio button 3";

2. "Radio button 3" The id and lay-filter of "Box 3" need to be consistent;

3. When obtaining elements, the jQuery method is used to find elements;

4. The method of finding elements needs to be changed according to different page layouts.

Recommended: layui usage tutorial

The above is the detailed content of Layui's method of listening to multiple radio events. 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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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