layer.open提交子页面的form和layedit文本编辑内容的方法
主要用到layer自带的取子页面dom的方法layer.getChildFrame(),在父页面对子页面dom进行操作
js代码:在layer.open中btnyesfunction(index,layero){}中获取子页面的dom进行操作:
$("a[name='editNews']").click(function(){
layer.open({
type:2,
title:'编辑',
shadeClose:true,
shade:0.8,
area:['99%','99%'],
offset:['2px'],
content:'/gcsoft/news/getNewsDetailById.action?itemId='+
$(this).attr("data-value"),
btn:['提交','取消'],
yes:function(index,layero){
//取子页面的form
varnewsFrom=layer.getChildFrame('#newsFrom',index);
//取子页面的layeidtLAY_layedit_1
varlayeditCt=layer.getChildFrame('#LAY_layedit_1',index).contents().find('body');
//获取layedit中的html标签并且赋值给子页面定义的Id为'content'textarea
layer.getChildFrame('#content',index).val(layeditCt[0].innerHTML);
if(newsFrom.find("#menuId").val()==''||
newsFrom.find("#menuId").val()==-1||newsFrom.find("#title").val()
==''){
layer.msg('标题和栏目不能为空');
return
}
//ajax提交
$.ajax({
type:"POST",
dataType:"json",
url:"/gcsoft/news/addOrUpdateNews.action",
data:newsFrom.serialize(),//newsForm序列化
success:function(result){
layer.msg('保存成功!');
layer.closeAll();
},
error:function(){
alert("异常!");
}
});
},
btn2:function(){
window.location.reload();
}
});
});
HTML代码:可以忽略不看
信息列表 新增/修改信息 新闻标题 ${news.title}#if>">