layer.open提交子页面的form和layedit文本编辑内容的

主要 用到layer 自带的取子页面dom的方法 layer.getChildFrame(),在父页面对子页面dom进行操作

js代码:在layer.open 中 btn yes function(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 var newsFrom = layer.getChildFrame('#newsFrom', index); //取子页面的layeidt LAY_layedit_1 var layeditCt = 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 代码: 可以忽略不看

<div> <div> <div> <nav aria-label="breadcrumb"> <ol> <li><a href="https://www.jb51.net/gcsoft/news/listAllNews.action" >信息列表</a></li> <li aria-current="page">新增/修改信息</li> </ol> </nav> <div> <div> <form method="post" > <div> <div> <div> <div> <span>新闻标题</span> </div> <input type="text" value="<#if news ??>${news.title}</#if>"> </div> </div> <div> <div> <div> <span>作者</span> </div> <input type="text" value="<#if news ??>${news.wen}</#if>"> <span> </span> </div> </div> </div> <div> <div> <div> <div> <label for="inputGroupSelect01">一级栏目</label> </div> <select ><option value="-1">------------------ 空 ------------------ </option></select> &nbsp; </div> </div> <div> <div> <div> <label for="inputGroupSelect01">二级栏目</label> </div> <select ><option value="-1">------------------ 空 ------------------ </option></select> &nbsp; </div> </div> <div> <div> <div> <label for="inputGroupSelect01">三级栏目</label> </div> <select><option value="-1">------------------ 空 ------------------ </option></select> &nbsp; </div> </div> <input type="hidden" check-type="required" value="<#if news ??>${news.menuId}<#else>0</#if>"> </div> <div> <div> <div> <input type="text" value="<#if news ??>${news.imgUrl}</#if>" > <div> <button type="button">上传图片</button> <button type="button" >删除图片</button> </div> </div> </div> <div> <div> <input type="text" value="<#if news ??>${news.videoUrl}</#if>" > <div> <button type="button">上传视频</button> <button type="button" >删除视频</button> </div> </div> </div> </div> <div> <div> <div> <div> <label for="inputGroupSelect01">部门</label> </div> <select data-rel="chosen" value="<#if news ??>${news.itemFrom}</#if>"> <#if dept ??> <#list dept as domainInfo> <#if news ??> <#if domainInfo.infoCode = news.origin> <option value="${domainInfo.infoCode}" selected="selected"> ${domainInfo.infoName} </option> <#else> <option value="${domainInfo.infoCode}"> ${domainInfo.infoName} </option> </#if> <#else> <option value="${domainInfo.infoCode}"> ${domainInfo.infoName} </option> </#if> </#list> </#if> </select> </div> </div> <div> <div> <div> <span>发表时间</span> </div> <input type="text" value="<#if news ??>${news.itemTime}</#if>"> <span> </span> </div> </div> <div> <div> <div> <span >排序</span> </div> <input type="text" value="<#if news ??>${news.orderBy}</#if>" οnkeyup="this.value=this.value.replace(/\D/g,'')"/> </div> </div> </div> <div> <div> <textarea><#if news ??>${news.content}</#if></textarea> <div> <div> <a href="javascript:void('1')" title="极小" v="1" role="option" aria-setsize="8" aria-posinset="1" tabindex="0"><span>极小(10px)</span></a> <a href="javascript:void('2')" title="特小" v="2" role="option" aria-setsize="8" aria-posinset="2" tabindex="0"><span>特小(12px)</span></a> <a href="javascript:void('3')" title="小" v="3" role="option" aria-setsize="8" aria-posinset="3" tabindex="0"><span>小(14px)</span></a> <a href="javascript:void('4')" title="默认" v="4" role="option" aria-setsize="8" aria-posinset="4" tabindex="0"><span>默认(16px)</span></a> <a href="javascript:void('5')" title="中" v="5" role="option" aria-setsize="8" aria-posinset="5" tabindex="0"><span>中(18px)</span></a> <a href="javascript:void('6')" title="大" v="6" role="option" aria-setsize="8" aria-posinset="6" tabindex="0"><span>大(24px)</span></a> <a href="javascript:void('7')" title="特大" v="7" role="option" aria-setsize="8" aria-posinset="7" tabindex="0"><span>特大(32px)</span></a> <a href="javascript:void('8')" title="极大" v="8" role="option" aria-setsize="8" aria-posinset="8" tabindex="0"><span>极大(48px)</span></a> </div> </div> </div> </div> <input type="hidden" value="<#if news ??>${news.itemId}</#if>"> </form> </div> </div> </div> </div> </div>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19a5c9e6e7c8143c478ed27a41b88b2f.html