1. 程式人生 > >layui使用button按鈕 點擊出現子彈層 彈層中載入表單,並傳遞引數給父彈出層

layui使用button按鈕 點擊出現子彈層 彈層中載入表單,並傳遞引數給父彈出層

在父層中增加button按鈕和隱藏域接收子彈出層傳遞的值

<button id="btnMenuTree" type="button" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-xs">選擇</button>
<input type="hidden" id="parentMenuId" name="parentMenuId" >
<input type="hidden" id="parentMenuName" name="parentMenuName" >

注意:button按鈕標籤中必須新增type="button"屬性否則將會有問題

在我的一開始的button中,沒有增加這個屬性,導致使用下面這種直接layer.open,開啟一個子彈出層的時候,開啟一瞬間就又關閉了,並且重新整理了頁面;使用parent.layer.open的時候則沒有問題,但是這就導致這兩個層級是同一級,而不是父子級,傳遞引數的時候會有很大的不方便。

載入type="button"這個屬性後,使用下面的程式碼開啟子彈出層則沒有問題,

$("#btnMenuTree").click( function () { 
		  layer.open({
	       	  type: 2,
	       	  title:"選單樹",
	       	  area: ['250px', '300px'],
	          content: "xxxx",
	          end: function(){ //銷燬時呼叫
	          }   
	      });
			
}); 

之後在子彈出層通過下面的程式碼給父彈出層傳遞值

parent.$('#parentMenuName').val(node.name);
parent.$('#parentMenuId').val(node.menuId);

 

參考自https://blog.csdn.net/qq_37306041/article/details/80411389