Home  >  Article  >  Web Front-end  >  How to declare global variables in layui.js

How to declare global variables in layui.js

藏色散人
藏色散人Original
2020-12-04 09:45:255098browse

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;".

How to declare global variables in layui.js

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!

Statement:
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