wangEditor 文本编辑器

参考:https://www.cnblogs.com/Scholars/p/8968838.html

下载:http://www.wangeditor.com/

前端代码:

复制代码
<script type="text/javascript">
    //下面这两行脚本就是弹出文本框
    var E = window.wangEditor
    var editor = new E('#editor')
    // 上传图片(举例)
    editor.customConfig.uploadImgServer = '/upload.ashx'

    //将网络图片隐藏掉
    editor.customConfig.showLinkImg = false

    // 将 timeout 时间改为 3s
    editor.customConfig.uploadImgTimeout = 1000 * 10;

    document.getElementById('btn1').addEventListener('click', function () {
        // 读取 html
        alert(editor.txt.html())
    }, false)

    editor.create();
</script>


<body>
     <form id="newspost" method="post" action="newspost" enctype="multipart/form-data">

    <input type="hidden" id="content" name="content"/>
    <div style="padding: 5px 0; color: #ccc"></div>
    <div id="editor"></div>
    <br/>
 
    </form>
    <button id="btn1">获取html</button>
</body>
复制代码

后端代码(一般处理程序):

复制代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace WebApplication1
{
    /// <summary>
    /// upload 的摘要说明
    /// </summary>
    public class upload : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";

            var files = context.Request.Files;
            if (files.Count <= 0)
            {
                return;
            }

            HttpPostedFile file = files[0];

            if (file == null)
            {
                context.Response.Write("error|file is null");
                return;
            }
            else
            {
                string Url = "http://192.168.0.20:8099/IMG/";

                string path = context.Server.MapPath("/Upader/Img/");  //存储图片的文件夹
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string originalFileName = file.FileName;
                string fileExtension = originalFileName.Substring(originalFileName.LastIndexOf('.'), originalFileName.Length - originalFileName.LastIndexOf('.'));
                string currentFileName = (new Random()).Next() + fileExtension;  //文件名中不要带中文,否则会出错
                                                                                 //生成文件路径
                string imagePath =  path + currentFileName;

                //保存文件
                file.SaveAs(imagePath);

                //获取图片url地址
                string imgUrl = "./Upader/Img/" + currentFileName;

                string Json = "{\"data\": [\"../../" + imgUrl.Replace(@"\", @"/") + "\"],\"errno\":\"0\"}";

                //返回图片url地址
                context.Response.Write(Json);
                return;
            }
        }

        

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    }
}

一般处理程序代码
复制代码

 

posted @   Tozhang  阅读(633)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示