How to use modularization in layui

王林
Release: 2020-11-30 14:01:00
Original
3481 people have browsed it

layui uses a modular approach: follow layui's module specifications to create an entry file, and load the entry file through the layui.use() method, such as [layui.use(['layer'], function(){var layer = layui.layer}].

How to use modularization in layui

The operating environment of this tutorial: Windows 10 system, layui version 2.5.6, this method is suitable for all brands Computer.

(Learning video sharing:javascript video tutorial)

Modular use:

Note: The introduced JS is:/layui/ layui.js

Follow layui's module specifications to create an entry file and load the entry file through layui.use()

Example:

    模块化的使用    
Copy after login

Additional: In order For convenience, you can use the following method to introduce

function deleteDictBatch(){ var form,layer; layui.use(['form','layer'],function () { form = layui.form; layer=layui.layer; }); //获取选中的元素的个数 var length_1 = $("[name='dictionaryCheckbox']:checked").length; //1.如果选中的个数为0,直接退出函数,提示选择字典删除 if(length_1 ==0 ){ layer.alert("请选中需要删除的字典") return ; } //如果有元素需要被删除 else{ if(!confirm("您确认要删除下列字典?")){//点取消也退出函数 return; } //第二种方式,以数组的方式去提交。后台用string接收 var values = []; $("[name='dictionaryCheckbox']:checked").each(function (i) {//i代表索引 values[i]=$(this).val(); }) $.post(contextPath+'/dictionary/deleteDictBatch.do',{dictionaryIds:values.toString()},function(response){ alert(response); if(response == "删除成功"){ getDictionaryTree();//查询字典树 getDictionaryFY();//分页查询字典信息 } },'text') //删除的业务逻辑 } }
Copy after login

, or you can introduce layer and form as global variables:

/** * @author: qlq * @time: 9:31 * @description: 添加培养方案的JS */ /** * 一次性自调函数初始化两个全局变量 */ var lyer,form; (function () { layui.use(['layer','form'],function () { layer=layui.layer,form=layui.form; }) })(); /** * 页面加载完成后执行一些函数 */ $(function () { layer.msg("消息框") }); /**********S *****************/
Copy after login

Related recommendations:layui

The above is the detailed content of How to use modularization in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!