html富文本编辑器

接了个单子,需要添加一个文章模块,一看用到的技术这么老,人傻了,纯html css js 。

在普通页面中

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
    <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <style>
        #editor—wrapper {
            border: 1px solid #ccc;
            z-index: 100;
        }

        #toolbar-container {
            border-bottom: 1px solid #ccc;
        }

        #editor-container {
            height: 500px;
        }

        .row {
            width: 98%;
            padding-left: 10px;
            padding-right: 10px;
            display: flex;
            justify-content: space-between;
        }

        .half-width {
            width: 45%;
        }

        .marginLeft {
            margin-left: 30px;
        }
    </style>
</head>

<body>

<div class="row marginLeft">
    <div id="editor—wrapper" class="half-width">
        <div id="toolbar-container"><!-- 工具栏 --></div>
        <div id="editor-container"><!-- 编辑器 --></div>
    </div>

    <div class="half-width">
        <h1 style="text-align: center; font-family: '楷体'; margin: 0 0; height: 10%;">展示效果</h1>
        <div id="editor-showNode"  style="border: 1px solid #ccc;height: 90%;"><!-- 编辑器 --></div>
    </div>
</div>

<div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
    <p style="margin-right: 10px; display: inline-block; margin-top: 13px;">文件名称:</p>
    <input style="display: inline-block; width: 80%;" type="text" class="form-control" placeholder="文件名称" aria-describedby="basic-addon2">
</div>

<div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
    <p style="margin-right: 10px; display: inline-block; margin-top: 13px;">添加备注:</p>
    <input style="display: inline-block; width: 80%;" type="text" class="form-control" placeholder="添加备注" aria-describedby="basic-addon2">
</div>
<br/>
<div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
    <p style="margin-right: 10px; display: inline-block; margin-top: 15px;">选择附件:</p>
    <input type="file" class="btn btn-primary" data-toggle="button" aria-pressed="false">
</div>

<div class="d-flex justify-content-center mb-3" style="margin-top: 80px; margin-left: -50px; margin-bottom: 40px">
    <button id="clear-editor" class="btn btn-primary" style="width: 300px;">提交公告摘要</button> <!-- 使用了Bootstrap的按钮样式 -->
</div>
<div style="height: 50px">

</div>

</body>

<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
<script>
    const { createEditor, createToolbar } = window.wangEditor

    const editorConfig = {
        placeholder: 'Type here...',
        onChange(editor) {
            const html = editor.getHtml()
            console.log('', html)  //html是当前编辑器的内容
            // 也可以同步到 <textarea>
            document.getElementById("editor-showNode").innerHTML=html;
        }
    }

    const editor = createEditor({
        selector: '#editor-container',
        html: '<p><br></p>',  //这是编辑器默认显示的内容
        config: editorConfig,
        mode: 'default', // or 'simple'
    })

    const toolbarConfig = {}

    const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'default', // or 'simple'
    });

    // 为按钮添加点击事件处理函数
    document.getElementById('clear-editor').addEventListener('click', function() {
        // 使用编辑器的 clear 方法来清空内容
        editor.clear()
    })
</script>

</html>

效果

在表单页面中,需要与要上传的文件一起添加到服务器

添加了一个隐藏的<textarea>标签来存储编辑器的内容,在提交表单时更新这个字段的值。改改了了按钮的点击事件处理函数,使其在提交表单时阻止默认的表单提交行为,并通过XMLHttpRequest发送一个POST请求,把所有内容提交到后台。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
    <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <style>
        #editor—wrapper {
            border: 1px solid #ccc;
            z-index: 100;
        }

        #toolbar-container {
            border-bottom: 1px solid #ccc;
        }

        #editor-container {
            height: 500px;
        }

        .row {
            width: 98%;
            padding-left: 10px;
            padding-right: 10px;
            display: flex;
            justify-content: space-between;
        }

        .half-width {
            width: 45%;
        }

        .marginLeft {
            margin-left: 30px;
        }
    </style>
</head>
<body>
<form id="myForm" method="post" enctype="multipart/form-data">
    <div class="row marginLeft">
        <div id="editor—wrapper" class="half-width">
            <div id="toolbar-container"><!-- 工具栏 --></div>
            <div id="editor-container"><!-- 编辑器 --></div>
        </div>
    
        <div class="half-width">
            <h1 style="text-align: center; font-family: '楷体'; margin: 0 0; height: 10%;">展示效果</h1>
            <div id="editor-showNode"  style="border: 1px solid #ccc;height: 90%;"><!-- 编辑器 --></div>
        </div>
    </div>

    <div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
        <p style="margin-right: 10px; display: inline-block; margin-top: 13px;">文件名称:</p>
        <input name="fileName" style="display: inline-block; width: 80%;" type="text" class="form-control" placeholder="文件名称" aria-describedby="basic-addon2">
    </div>

    <div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
        <p style="margin-right: 10px; display: inline-block; margin-top: 13px;">添加备注:</p>
        <input name="note" style="display: inline-block; width: 80%;" type="text" class="form-control" placeholder="添加备注" aria-describedby="basic-addon2">
    </div>

    <div class="marginLeft" style="margin-top: 50px; display: flex; align-items: center;">
        <p style="margin-right: 10px; display: inline-block; margin-top: 15px;">选择附件:</p>
        <input name="file" type="file" class="btn btn-primary" data-toggle="button" aria-pressed="false">
    </div>

    <textarea id="editorContent" name="editorContent" style="display: none;"></textarea>

    <div class="d-flex justify-content-center mb-3" style="margin-top: 80px; margin-left: -50px; margin-bottom: 40px">
        <button id="submit" class="btn btn-primary" style="width: 300px;">提交公告摘要</button>
    </div>
</form>

<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>

<script>
    const { createEditor, createToolbar } = window.wangEditor

    const editorConfig = {
        placeholder: 'Type here...',
        onChange(editor) {
            const html = editor.getHtml()
            console.log('', html)
            document.getElementById("editor-showNode").innerHTML=html;
        }
    }

    const editor = createEditor({
        selector: '#editor-container',
        html: '<p><br></p>',  
        config: editorConfig,
        mode: 'default', 
    })

    const toolbarConfig = {}

    const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'default',
    });

    document.getElementById('submit').addEventListener('click', function(event) {
        event.preventDefault();  

        document.getElementById('editorContent').value = editor.getHtml();

        var formElement = document.querySelector("form");
        var formData = new FormData(formElement);

        var request = new XMLHttpRequest();  
        request.open("POST", "/submit"); 
        request.send(formData);  
    })
</script>
</body>
</html>

效果

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/55374.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

DAY01_Spring简介IOC、DI入门案例Bean基础配置Bean实例化Bean生命周期依赖注入(DI配置)

目录 一 Spring1 Spring简介1.1 为什么要学1.2 学什么1.3 怎么学 2 初识Spring2.1 Spring家族2.2 Spring发展史 3 Spring体系结构问题导入3.1 Spring Framework系统架构图3.2 Spring Framework课程学习路线 4 Spring核心概念问题导入4.1 目前我们代码存在的问题4.2 核心概念 二…

【计算机网络】408统考2014年题36

题目描述 【2014年题36】主机甲与主机乙之间使用后退N帧(GBN)协议传输数据&#xff0c;甲的发送窗口尺寸为1000&#xff0c;数据帧长为1000字节&#xff0c;信道带宽为100Mbps&#xff0c;乙每收到一个数据帧就立即利用一个短帧&#xff08;忽略其传输延迟&#xff09;进行确认…

利用vscode--sftp,将本地项目/文件上传到远程服务器中详细教程

1、首先在 vscode 中下载 sftp&#xff1a; 2、然后在 vscode 中打开本地将要上传的项目或文件&#xff1a; 3、安装完后&#xff0c;使用快捷键 ctrlshiftP 打开指令窗口&#xff0c;输入 sftp:config &#xff0c;回车&#xff0c;在当前目录中会自动生成 .vscode 文件夹及 s…

Java面向对象之方法的使用

文章目录 一、什么是方法二、方法的声明格式三、方法的分类四、方法的调用五、方法的注意点六、方法的重载七、可变形参的方法八、方法参数的值传递机制九、递归方法 一、什么是方法 方法(method)是类或对象行为特征的抽象&#xff0c;用来完成某个功能操作。在某些语言中也称…

【设计模式——学习笔记】23种设计模式——代理模式Proxy(原理讲解+应用场景介绍+案例介绍+Java代码实现)

介绍 基础介绍 代理模式为一个对象提供一个代理对象&#xff0c;以控制对这个对象的访问。即通过代理对象访问目标对象&#xff0c;这样做的好处是&#xff1a;可以在不修改目标对象代码的基础上&#xff0c;增强额外的功能操作&#xff0c;即扩展目标对象的功能被代理的对象…

Go学习第一天

闲聊两句 从事java后端开发8年多&#xff0c;期间也曾零星看过Go语言、Python、Erlang等等&#xff0c;但都未曾认真学习过&#xff0c;恰好公司最近项目需要&#xff0c;之前用Go开发的项目因为同事离职&#xff0c;暂未人来接手&#xff0c;所以老大就找到我和另外一个同事&…

【RabbitMQ(day3)】扇形交换机和主题交换机的应用

文章目录 第三种模型&#xff08;Publish/Subscribe 发布/订阅&#xff09;扇型&#xff08;funout&#xff09;交换机Public/Subscribe 模型绑定 第四、第五种模型&#xff08;Routing、Topics&#xff09;第四种模型&#xff08;Routing&#xff09;主题交换机&#xff08;To…

使用css和js给按钮添加微交互的几种方式

使用css和js给按钮添加微交互的几种方式 在现实世界中&#xff0c;当我们轻弹或按下某些东西时&#xff0c;它们会发出咔嗒声&#xff0c;例如电灯开关。有些东西会亮起或发出蜂鸣声&#xff0c;这些响应都是“微交互”&#xff0c;让我们知道我们何时成功完成了某件事。在本文…

一起学数据结构(2)——线性表及线性表顺序实现

目录 1. 什么是数据结构&#xff1a; 1.1 数据结构的研究内容&#xff1a; 1.2 数据结构的基本概念&#xff1a; 1.2.1 逻辑结构&#xff1a; 1.2.2 存储结构&#xff1a; 2. 线性表&#xff1a; 2.1 线性表的基本定义&#xff1a; 2.2 线性表的运用&#xff1a; 3 .线性…

对话CSDN副总裁-邹欣:先行动的才是赢家,践行长期主义的价值创造者终将收获价值 | COC上海城市开发者社区

文章目录 ⭐️ COC上海城市开发者社区的首次集结契机⭐️ 关于 "技术人如何应对35岁中年危机"&#x1f31f; 30岁了没转管理&#xff0c;应该焦虑么&#xff1f;&#x1f31f; 30岁没转管理&#xff0c;是否还有其他选择&#xff1f; ⭐️ 践行长期主义的价值创造者终…

DHorse v1.3.0 发布,基于k8s的发布平台

综述 DHorse是一个简单易用、以应用为中心的云原生DevOps系统&#xff0c;具有持续集成、持续部署、微服务治理等功能&#xff0c;无需安装依赖Docker、Maven、Node等环境即可发布Java、Vue、React应用&#xff0c;主要特点&#xff1a;部署简单、操作简洁、功能快速。 新增特…

AI情绪鼓励师(基于PALM 2.0 finetune)

AI情绪鼓励师&#xff08;基于PALM 2.0 finetune) 目录 一、写在前面的话 二、前言 三、获取用于finetune的“夸夸”数据集 四、 获取并finetune PALM 2.0 预训练生成模型 模型 五、模型调用应用 一、写在前面的话 从小我就是极端内向和社恐的孩子&#xff0c;我普通之极…

【Uniapp 中实现微信登录】

要在 Uniapp 中实现微信登录&#xff0c;需要完成以下步骤&#xff1a; 在微信开放平台注册一个应用&#xff0c;并获取到该应用的 AppID 和 AppSecret。 在 manifest.json 中点击App模块配置。勾选微信登录模块&#xff0c;填入该应用的 AppID 在代码中调用 uni.login 方法&…

算法训练营第五十七天||647.回文子串、516.最长回文子序列、动态规划总结

647.回文子串 出自代码随想录 如果大家做了很多这种子序列相关的题目&#xff0c;在定义dp数组的时候 很自然就会想题目求什么&#xff0c;我们就如何定义dp数组。 绝大多数题目确实是这样&#xff0c;不过本题如果我们定义&#xff0c;dp[i] 为 下标i结尾的字符串有 dp[i]个…

IntelliJ IDEA 2023.2新特性详解第二弹!

4 性能分析器 4.1 从 Run&#xff08;运行&#xff09;工具窗口使用分析功能 2023.2 中&#xff0c;可直接从 Run&#xff08;运行&#xff09;工具窗口轻松访问 IntelliJ 分析器的功能。 使用新按钮&#xff0c;点击即可调用&#xff1a; Attach IntelliJ Profiler&#xff…

【Java多线程学习4】volatile关键字及其作用

说说对于volatile关键字的理解&#xff0c;及的作用 概述 1、我们知道要想线程安全&#xff0c;就需要保证三大特性&#xff1a;原子性&#xff0c;有序性&#xff0c;可见性。 2、被volatile关键字修饰的变量&#xff0c;可以保证其可见性和有序性&#xff0c;但是volatile…

实验-路由器配置静态路由

软件&#xff1a;cicso packet tracer 8.0 拓扑图&#xff1a;路由器&#xff1a;Router-PT、连接线&#xff1a;Serial DTE、连接口&#xff1a;Serial口&#xff08;serial是串行口,一般用于连接设备,不能连接电脑&#xff09; 实验步骤&#xff1a; 1、构建拓扑图&#xf…

pytorch学习——正则化技术——权重衰减

一、概念介绍 权重衰减&#xff08;Weight Decay&#xff09;是一种常用的正则化技术&#xff0c;它通过在损失函数中添加一个惩罚项来限制模型的复杂度&#xff0c;从而防止过拟合。 在训练参数化机器学习模型时&#xff0c; 权重衰减&#xff08;weight decay&#xff09;是…

windows环境下adb 下载和配置,连接手机。

ADB下载地址&#xff1a; https://adbdownload.com/ 选择下载windows系统的。 下载后解压&#xff0c;查看adb.exe所在的目录&#xff0c;如下 这里将路径复制下来&#xff1a;D:\ADB 配置到系统环境变量中。 然后再打开cmd&#xff0c;输入adb version查看版本。 出现…

2023.8.1号论文阅读

文章目录 MCPA: Multi-scale Cross Perceptron Attention Network for 2D Medical Image Segmentation摘要本文方法实验结果 SwinMM: Masked Multi-view with SwinTransformers for 3D Medical Image Segmentation摘要本文方法实验结果 MCPA: Multi-scale Cross Perceptron Att…