Layui.js global variable declaration method: first open the parent page and child page code; then declare the global variable by cutting the value of the link in the child page, such as "var $proId = theRequest.projectId;".
The operating environment of this tutorial: Windows 7 system, layui version 2.4. This method is suitable for all brands of computers.
Recommended: "javascript basic tutorial" "layUI tutorial"
layui is a front-end UI framework written using its own module specifications, following The writing and organization form of native HTML/CSS/JS has a very low threshold and is ready to use. It is minimalist on the outside but full on the inside. It is light in size and rich in components. Every detail from the core code to the API has been carefully crafted, making it very suitable for rapid interface development.
How to declare global variables in layui.js?
layui New way to write global variables: You can declare global variables by cutting the value of --link-- in the sub-page
Code of parent page:
case 'detail': if (data.length === 0) { layer.msg('请选择一行'); } else if ( data[0].projectId ) { parent.layer.open({ type: 2, anim:1, title: '查看详情', maxmin: true, area: ['85%', '95%'], content: '/static/views/iframe/project/detail.html?projectId='+data[0].projectId +'&t='+ Date.now(), //在链接上加入项目id,在子页面截取 success: function (layero, index) { //projectId 在子页面截取,全局使用! var body = parent.layer.getChildFrame('body', index); // body.find('#projectId').val(data[0].projectId) } }); }else{ layer.msg('请刷新页面,再次操作即可') } break;
Code of sub-page
//这段代码通用: var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); } } var $proId = theRequest.projectId; //声明全局项目id
Note:
This code is placed outside layui.use
The above is the detailed content of How to declare global variables in layui.js. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
