layer⽗窗⼝调⽤⼦窗⼝函数例⼦
⼦窗⼝html,⼀个弹出框,⾥⾯有各种form选项:
<html xmlns="/1999/xhtml">
<head>
<title>fixed display number page</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
<meta http-equiv="description" content="This is my page" />
<link href="<%=path%>/res/main.css" rel="stylesheet" type="text/css" />
<script src="<%=path%>/res/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="<%=path %>/res/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=path%>/res/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="<%=path%>/res/js/fig.js"></script>
ajax实例里面的函数
<link rel='stylesheet' type='text/css' href="<%=path%>/res/js/ueditor/themes/default/css/ueditor.css"/>
<script type="text/javascript" src="<%=path%>/res/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<style>
#fixed-display-number-page-form{
margin-left:5%;
margin-top:5%;
}
</style>
</head>
<body>
<span id="fixed-display-number-page-form-radio" >${batch.displayNumType}</span>
<span id="fixed-display-number-page-batchId" >${batch.batchId}</span>
<form  id="fixed-display-number-page-form">
<input type="radio" name="displayNumber" id="displayNumberRadio" checked="checked"  value="1" />固定外显
<select id="fixed-display-number-page-form-radio-select1">
<c:forEach var="obj" items="${fixedDisplayNumberList}">
<option <c:if test="${batch.displayNum==obj.fixedDisplayNumber}">selected="selected"</c:if> value="
${obj.fixedDisplayNumber}">${obj.fixedDisplayNumber}</option>  </c:forEach>
</select>
<br/>
<input type="radio" name="displayNumber" id="displayNumberRadio" value="2" />随机外显
<br/>
<input type="radio" name="displayNumber" id="displayNumberRadio" value="3" />本⽹固定外显+他⽹随机外显
<select id="fixed-display-number-page-form-radio-select2">
<c:forEach var="obj" items="${fixedDisplayNumberList}">
<option <c:if test="${batch.displayNum==obj.fixedDisplayNumber}">selected="selected"</c:if> value="${obj.fixedDisplayNumber}">${obj.fixedDisplayNumber}</option>  </c:forEach>
</select>
</form>
<script>
$(document).ready(function(){
//取span的值
var radioValue = $("#fixed-display-number-page-form-radio").html();
$("input[name='displayNumber'][value='"+radioValue+"'").attr("checked",true);
$.fn.saveFixedDisplayNumber=function(){
//保存数据
var displayNumType=$("input[name='displayNumber']:checked").val();
// var displayNum=$("#fixed-display-number-page-form-radio-select option[selected]").val();
displayNum=$("#fixed-display-number-page-form-radio-select option:selected").val();
if(displayNumType==1){
ElementById("fixed-display-number-page-form-radio-select1").value;
}else if(displayNumType==3){
ElementById("fixed-display-number-page-form-radio-select2").value;
}else{
displayNum=null;
}
let batchId=$("#fixed-display-number-page-batchId").html();
//请求数据给后台
var url="<%=path%>/batch/saveDisplayNumber";
postData(displayNum,displayNumType,batchId,url);
}
function postData(displayNum,displayNumType,batchId,url){
$.ajax({
type:"POST",
url:url,
cache:false,
data:{
"displayNum":displayNum,
"displayNumType":displayNumType,
"batchId":batchId
},
async:false,
success:function(data){
data=JSON.parse(data);
var de;
var sg;
if(code==0){
alert("保存成功");
}else{
alert(errmsg);
}
},
error:function(jqXHR, textStatus, errorThrown){
alert("请求失败");
},
complete:function(){
}
});
}
});
function saveFixedDisplayNumber(){
$().saveFixedDisplayNumber();
}
</script>
</body>
</html>
⽗窗⼝调⽤实例:
function displayNumberSetting(id){
layer.open({
id:id,
//skin: 'layui-layer-molv', //样式类名
type: 2,
title: '外显配置',
shadeClose: true,
shade: false,
maxmin: true, //开启最⼤化最⼩化按钮
btn:['保存','关闭'],
area: ['435px', '300px'],
content: '<%=path%>/batch/fixedDisplayNumberPage?batchId='+id,
yes: function(index,layero) {
var body = ChildFrame('body', index);
var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗⼝对象              //执⾏iframe页的⽅法
//hod();
//得到iframe页的body内容
//console.log("Iframe内容:"+body.html());
//调⽤iframe的⽅法
iframeWin.saveFixedDisplayNumber();
layer.close(index); //关闭弹窗
//保存form的⽤户数据
},
cancel: function(){
//do nothing
}
});
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。