前言
上一篇解決了,在layui
中子頁面傳值回父頁面的問題。
這一篇主要總結:子頁面傳值回父頁面后,賦值的兩種方式:文本框賦值;表格賦值。
文本框賦值
文本框賦值的方式,相對的簡單。只需獲取到子頁面的值后,轉換成對象后,直接賦值即可。代碼如下所示:
parent.layer.open({
type: 2,
title: '標題信息',
amin: 4,
shadeClose: true,
shade: 0.8,
area: ['55%', '65%'],
btn: ["確定", '關閉'],
content: '../TankInPlan/HtReferList',
success: function (layero, index) { },
yes: function (index, layero) {
var obj = $(layero).find("iframe")[0].contentWindow;
$(layero).find("iframe")[0].contentWindow.$('#saveBtn').click();//執行子頁面的按鈕點擊事件
var mJson = obj.$('#uidsub').val();//1.取值
if (mJson != "") {
var _mJson = $.parseJSON(mJson);//2.轉換成對象
$("#uCompId").val(_mJson[0].uCompId);//3.賦值
$("#cCompCode").val(_mJson[0].cCompCode);
$("#cCltName").val(_mJson[0].cCltName);
}
},
});
表格賦值
表格賦值,可能有人會很納悶。表格賦值和文本框賦值難道還不一樣嗎?文本框賦可以直接賦值,但是,表格需要找到對應的子元素才能賦值。代碼如下所示:
<table class="layui-table" id="tabCLXX" style="margin:0px;">
<thead>
<tr>
<th>車牌號碼</th>
<th>掛車號碼</th>
<th>司機姓名1</th>
<th>身份證號1</th>
<th>手機號1</th>
<th>司機姓名2</th>
<th>身份證號2</th>
<th>手機號2</th>
<th>裝車數量</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr class="list">
<td><input type="text" lay-verify="required" class="layui-input" ondblclick="ShowCPHM(this)" /></td>
<td><input type="text" class="layui-input" name="cCarGuaNo" /></td>
<td><input type="text" lay-verify="required" class="layui-input"/></td>
<td><input type="text" class="layui-input"/></td>
<td><input type="text" class="layui-input" /></td>
<td><input type="text" class="layui-input" /></td>
<td><input type="text" class="layui-input" /></td>
<td><input type="text" class="layui-input" /></td>
<td><input type="text" class="layui-input" value="0.000" /></td>
<td><button class="layui-btn layui-btn-danger btnDelRow">刪除</button></td>
</tr>
</tbody>
</table>
function ShowCPHM(objs){
parent.layer.open({
type: 2,
title: '標題信息',
amin: 4,
shadeClose: true,
shade: 0.8,
area: ['55%', '65%'],
btn: ["確定", '關閉'],
content: 'url路徑',
success: function (layero, index) { },
yes: function (index, layero) {
var obj = $(layero).find("iframe")[0].contentWindow;
$(layero).find("iframe")[0].contentWindow.$('#saveBtn').click();//執行子頁面的按鈕點擊事件
var mJson = obj.$('#uidsub').val();//1.取值
if (mJson != "") {
var _mJson = $.parseJSON(mJson);//2.轉換成對象
$(objs).val(_mJson[0].cCarNO);//3.給第一個input 賦值
$(objs).parent().next().children().val(_mJson[0].cGuaChe);//給第二個input賦值
}
},
});
}
你知道的越多,你不知道的越多。我們不生產知識,我們只是知識的搬運工。