参考文档:
新人必看:http://layer.layui.com/hello.html
开发文档:https://www.layui.com/doc/modules/layer.html#layer.close
主页:http://layer.layui.com/
一个参考demo : https://www.cnblogs.com/jiqing9006/p/5135697.html
js文件:链接: https://pan.baidu.com/s/1M7CLVmRrkCl7Rhc6KPG5iQ 提取码: 9h47
父页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>form表单</title>
<script type="text/javascript" src="layer/jquery.min.js"></script>
<script src="layer/layer.js"></script>
</head>
<body>
<form name="myform" id="myform" action="{:U('Enterprise/add_job_post')}" method="post" class="main-ul-box" enctype="multipart/form-data" style="margin-top:93px;">
<div class="weui-cell ding-address">
<div class="weui-cell__hd">
<label for="" class="weui-label color-label">地址</label>
</div>
<div class="weui-cell__bd">
<a href="javascript:void(0)" class="weui_btn weui_btn_primary dingwei-box" id="iframes">
<input class="layui-btn" type="text" id="job_address" value=""/>
</a>
</div>
</div>
<input class="weui-btn login-btn" value="确认发布" type="button">
</form>
</body>
<script>
//弹出一个iframe层
$('#iframes').on('click', function(){
// 禁用按钮防止重复提交
$("#job_address").attr({ disabled: "disabled" });//不加的话容易滑屏...
layer.open({
type: 2,
title: 'iframe父子操作',
maxmin: false,
shadeClose: true, //点击遮罩关闭层
area: ['350px', '80%'],
content: ["index.html",'no']
});
});
</script>
</html>
子页面
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>选择位置</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<style type="text/css">
html,body{height:100%; width:100%; overflow:hidden; margin:0;
padding:0;}
body{
height:100%; width:100%; overflow:hidden; margin:0;
padding:0;
}
div{height:83%;}
}
</style>
</head>
<body>
<div class="con">
<iframe id="mapPage" width="100%" height="100%" src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=6NVBZ-YA43F-UHLJY-JS3WK-26HQH-7ZBLM&referer=灵工邦" >
</iframe>
</div>
<input type="hidden" id="lat"/>
<input type="hidden" id="lng" />
<input type="hidden" id="poiaddress" />
<input type="hidden" id="cityname" />
<input type="hidden" id="poiname" />
<input class="weui-btn login-btn" id="gb" value="提交" type="button">
<script src="layer/layer.js"></script>
<script type="text/javascript" src="layer/jquery.min.js"></script>
<script>
window.addEventListener('message', function(event) { //地图监听事件
var loc = event.data;
if (loc && loc.module == 'locationPicker') {//赋值到input框
$("#lat").val(loc.latlng.lat);//纬度
$("#lng").val(loc.latlng.lng);//经度
$("#poiaddress").val(loc.poiaddress);//详细地址
$("#cityname").val(loc.cityname);//市
$("#poiname").val(loc.poiname);//地址 例:XX小区 即名称
}
}, false);
$(function(){
/* $('#button').click(function(){
var lat=$('#lat').val();
var lng=$('#lng').val();
$.ajax({
type: "post",
url: "{:U('Map/mapEdit')}",
data: {lat:lat,lng:lng},//提交到demo.php的数据
dataType: "json",//回调函数接收数据的数据格式
success: function(msg){
if(msg!='' && msg.code==200){
alert(msg.info.lat);
alert(msg.info.lng);
window.location.href='http://www.baidu.com';//跳转地址
}
},
error:function(msg){
console.log(msg);
}
});
}); */
$('#gb').on('click', function(){
var poiname=$('#poiname').val();//获取input框的值
parent.$("#job_address").val(poiname);//传递值到父页面
parent.$("#formBtn").removeAttr("disabled");//解除input限制
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
parent.layer.close(index); //再执行关闭当前iframe窗口
});
});
</script>
</body>
</html>