Home > Web Front-end > JS Tutorial > An example of assigning values ​​​​from layer sub-layers to parent layer page elements

An example of assigning values ​​​​from layer sub-layers to parent layer page elements

小云云
Release: 2018-02-03 13:05:59
Original
2986 people have browsed it

This article mainly brings you an example of how the layer sub-layer assigns values ​​to the parent layer page elements to achieve the effect of transferring values ​​​​to the parent layer page. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.

Parent layer:

jsp:

//Add a hidden input box on the page to be used to set the value of the child layer, thereby setting the value of the child layer Data is passed to this page

<input type="hidden" id="getValue" name="getValue" value="" />
Copy after login

js code:

//Set function, when executed, pop up the sub-window and pass the current window name

//弹出子窗口(选择商家)
 function choseMerchant() {

  //获取当前窗口名称
  var parentName= window.name;

  /*(由于用的ssm框架)URL对应的是controller方法,并向其传递当前窗口名称,打开的窗口显示页面即    
  为经过controller方法后返回的页面*/
  var url = root + "/adPosition/choseMerchant?parentName="+ parentName;

  laySum = parent.layer.open({
   //设置打开的子窗口效果
   type : 2,
   title : "选择商家",
   shadeClose : true,
   shade : 0.5,
   shift : 0,
   area : [ '40%', '863px' ],
   content : url,
   success: function(layero, index){ 
   }
  });
 }
Copy after login

Sub-layer:

In jsp:

//The hidden input box added to the page, the stored value is the name of the parent window returned after the controller method, used for differentiation, set the id to mainIframeName

<input type="hidden" id="mainIframeName" name="mainIframeName" value="${parentName}">
Copy after login

js code:

//Set function, when executed, pass the value and close the current window

function setvalue() {

  //得到“mainIframeName”输入框中存储的值
  var mainIframeName = $("#mainIframeName").val();

  //判断是否为空或者是未定义
  if (mainIframeName != "" && mainIframeName != "undefined") 
  {
  //此处的ifrc和winc的意义可自行查阅
  var ifrc = window.parent.frames[mainIframeName];
  var winc = ifrc.window || ifrc.contentWindow;
  try {
   //设置父窗口隐藏输入框的值为hello world
   winc.document.getElementById("getValue").value = "hello world!";
   } catch (ex) {
    winc.location.reload();
   }
  }
   //关闭当前窗口
   var index = parent.layer.getFrameIndex(window.name);
   parent.layer.close(index);
 }
Copy after login

Summary: This method is used for child layers to directly assign values ​​​​to parent layer elements to achieve The key point of the value-passing effect is that the parent layer window name needs to be passed to the child layer.

The above is the entire content of the example of assigning values ​​​​to parent layer page elements by the layer sub-layer brought by the editor to achieve the effect of transferring values ​​​​to the parent layer page. I hope you like it~

Related recommendations:

jQuery automatically assigns values ​​to form elements based on json objects

The above is the detailed content of An example of assigning values ​​​​from layer sub-layers to parent layer page elements. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template