1.页面效果
父页面获取到弹框中TInyMCE编辑器的值并显示在父页面中,实现思想:
在弹框中定义一个隐藏的文本框,从弹框中获取到编辑器的值赋值给文本框,父页面获取文本框的值。
2.代码如下:
弹框页面:children.html
<div class="layui-input-block">
<textarea name="supplyservice" id="supplyservice" ></textarea>
</div>
<textarea name="" id="hiddensupplyservice" style="display: none"></textarea>
</div>
//弹框的js中初始化TInyMCE ,通过离焦事件获取到TinyMCE中的内容
tinymce.init({
selector:"#supplyservice",
language:"zh_CN",
min_height:300,
plugins: [
"advlist autolink lists link image charmap preview",
"searchreplace visualblocks fullscreen",
"insertdatetime table contextmenu paste",
"emoticons textcolor autoresize autosave"
],
toolbar1: "undo redo | styleselect | fontselect | fontsizeselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
toolbar2: "fullscreen preview | forecolor backcolor emoticons | table | link image| mybutton |restoredraft",
images_upload_url:'上传的后台接口',
setup:function(editor){
editor.on('blur',function (){
$("#hiddensupplyservice").html(tinyMCE.activeEditor.getContent());
})
}
});
父页面获取值
layui.layer.open({
title:"测试详情",
type:2,
maxmin:true,
area:['1200px','100%'],
content:"children.html",
btn:['保存','取消'],
btnAlign:'c',
yes:function (index,layero) {
//点击保存按钮,关闭弹框并进行数据渲染
var iframe= $(layero).find('iframe').contents();
alert(iframe.find('#hiddensupplyservice').html());
form.render();
layui.layer.close(index);
}
});