layer.open提交子頁面的form和layedit文本編輯內(nèi)容的方法
主要 用到layer 自帶的取子頁面dom的方法 layer.getChildFrame(),在父頁面對子頁面dom進(jìn)行操作
js代碼:在layer.open 中 btn yes function(index, layero){ }中 獲取子頁面的dom 進(jìn)行操作:
$("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標(biāo)簽 并且賦值給子頁面定義的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('標(biāo)題和欄目不能為空'); 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 class="container-fluid"> <div class="row-fluid"> <div class="box"> <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="/gcsoft/news/listAllNews.action" rel="external nofollow" >信息列表</a></li> <li class="breadcrumb-item active" aria-current="page">新增/修改信息</li> </ol> </nav> <div> <div class="container"> <form id="newsFrom" class="form-horizontal input-prepend" method="post" > <div class="row"> <div class="col-sm-6"> <div class="input-group mb-4"> <div class="input-group-prepend"> <span class="input-group-text">新聞標(biāo)題</span> </div> <input type="text" class="form-control" id="title" name="title" value="<#if news ??>${news.title}</#if>"> </div> </div> <div class="col-sm-6"> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">作者</span> </div> <input type="text" class="form-control" id="wen" name="wen" value="<#if news ??>${news.wen}</#if>"> <span id="wen_span" class="help-inline"> </span> </div> </div> </div> <div class="row"> <div class="col-sm-4"> <div class="input-group mb-3"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect01">一級欄目</label> </div> <select class="custom-select" id="Select1" ><option value="-1">------------------ 空 ------------------ </option></select> </div> </div> <div class="col-sm-4"> <div class="input-group mb-3"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect01">二級欄目</label> </div> <select class="custom-select" id="Select2" ><option value="-1">------------------ 空 ------------------ </option></select> </div> </div> <div class="col-sm-4"> <div class="input-group mb-3"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect01">三級欄目</label> </div> <select class="custom-select" id="Select3"><option value="-1">------------------ 空 ------------------ </option></select> </div> </div> <input type="hidden" check-type="required" id="menuId" name="menuId" value="<#if news ??>${news.menuId}<#else>0</#if>"> </div> <div class="row"> <div class="col-sm-6"> <div class="input-group mb-3"> <input type="text" class="form-control" name="imgUrl" id="imgUrl" value="<#if news ??>${news.imgUrl}</#if>" > <div class="input-group-append"> <button class="btn btn-outline-secondary" type="button" id="imageUpload">上傳圖片</button> <button class="btn btn-outline-secondary" type="button" id="imageDele" >刪除圖片</button> </div> </div> </div> <div class="col-sm-6"> <div class="input-group mb-3"> <input type="text" class="form-control" name="videoUrl" id="videoUrl" value="<#if news ??>${news.videoUrl}</#if>" > <div class="input-group-append"> <button class="btn btn-outline-secondary" type="button" id="videoUpload">上傳視頻</button> <button class="btn btn-outline-secondary" type="button" id="videoDele" >刪除視頻</button> </div> </div> </div> </div> <div class="row"> <div class="col-sm-3"> <div class="input-group mb-4"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect01">部門</label> </div> <select class="custom-select" data-rel="chosen" id="origin" name="origin" 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 class="col-sm-3"> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">發(fā)表時間</span> </div> <input type="text" class="form-control datepicker" id="itemTime" name="itemTime" value="<#if news ??>${news.itemTime}</#if>"> <span id="itemTime_span" class="help-inline"> </span> </div> </div> <div class="col-sm-2"> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text" >排序</span> </div> <input type="text" class="form-control" id="orderBy" name="orderBy" value="<#if news ??>${news.orderBy}</#if>" οnkeyup="this.value=this.value.replace(/\D/g,'')"/> </div> </div> </div> <div class="row"> <div class="col-sm-12" style="margin-bottom: 20px"> <textarea name="content" id="content" style="display: none;"><#if news ??>${news.content}</#if></textarea> <div id="xhePanel" style="top: 50px;left: 50px;"> <div class="xheMenu"> <a href="javascript:void('1')" rel="external nofollow" title="極小" v="1" role="option" aria-setsize="8" aria-posinset="1" tabindex="0"><span style="font-size:10px;">極小(10px)</span></a> <a href="javascript:void('2')" rel="external nofollow" title="特小" v="2" role="option" aria-setsize="8" aria-posinset="2" tabindex="0"><span style="font-size:12px;">特小(12px)</span></a> <a href="javascript:void('3')" rel="external nofollow" title="小" v="3" role="option" aria-setsize="8" aria-posinset="3" tabindex="0"><span style="font-size:14px;">小(14px)</span></a> <a href="javascript:void('4')" rel="external nofollow" title="默認(rèn)" v="4" role="option" aria-setsize="8" aria-posinset="4" tabindex="0"><span style="font-size:16px;">默認(rèn)(16px)</span></a> <a href="javascript:void('5')" rel="external nofollow" title="中" v="5" role="option" aria-setsize="8" aria-posinset="5" tabindex="0"><span style="font-size:18px;">中(18px)</span></a> <a href="javascript:void('6')" rel="external nofollow" title="大" v="6" role="option" aria-setsize="8" aria-posinset="6" tabindex="0"><span style="font-size:24px;">大(24px)</span></a> <a href="javascript:void('7')" rel="external nofollow" title="特大" v="7" role="option" aria-setsize="8" aria-posinset="7" tabindex="0"><span style="font-size:32px;">特大(32px)</span></a> <a href="javascript:void('8')" rel="external nofollow" title="極大" v="8" role="option" aria-setsize="8" aria-posinset="8" tabindex="0"><span style="font-size:48px;">極大(48px)</span></a> </div> </div> </div> </div> <input type="hidden" id="itemId" name="itemId" value="<#if news ??>${news.itemId}</#if>"> </form> </div> </div> </div> </div> </div>
以上這篇layer.open提交子頁面的form和layedit文本編輯內(nèi)容的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
javascript實(shí)現(xiàn)動態(tài)加載CSS
最近在做自己的小框架的按需加載模塊,那么就需要做到異步動態(tài)加載css文件。仔細(xì)研究了一番,得到了如下解決方案,分享給大家。2015-01-01- 使用js模擬類繼承小例子,學(xué)習(xí)js面向?qū)ο蟮呐笥芽梢詤⒖枷隆?/div> 2010-07-07
在Postman的腳本中如何使用pm對象獲取接口的請求參數(shù)
這篇文章主要介紹了在Postman的腳本中如何使用pm對象獲取接口的請求參數(shù),本文通過實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09微信小程序?qū)崿F(xiàn)動態(tài)設(shè)置placeholder提示文字及按鈕選中/取消狀態(tài)的方法
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)動態(tài)設(shè)置placeholder提示文字及按鈕選中/取消狀態(tài)的方法,涉及事件綁定及this.setData動態(tài)設(shè)置屬性數(shù)據(jù)的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12JavaScript樹的深度優(yōu)先遍歷和廣度優(yōu)先遍歷算法示例
這篇文章主要介紹了JavaScript樹的深度優(yōu)先遍歷和廣度優(yōu)先遍歷算法,結(jié)合實(shí)例形式分析了JavaScript樹的深度優(yōu)先遍歷、廣度優(yōu)先遍歷遞歸與非遞歸相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-07-07淺談layui 綁定form submit提交表單的注意事項(xiàng)
今天小編就為大家分享一篇淺談layui 綁定form submit提交表單的注意事項(xiàng),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10最新評論