去官网下载,本Demo用的MVC模式

下载地址:http://ueditor.baidu.com/website/download.html

加入文件夹中的结构:

引入了函数公式的图标:

@{ViewBag.Title = "Index";
}@*配置文件*@
<script src="~/Scripts/ueditor/ueditor.config.js"></script>
<script src="~/Scripts/ueditor/ueditor.all.min.js"></script>
<link href="~/Scripts/ueditor/themes/iframe.css" rel="stylesheet" />
<script src="~/Scripts/ueditor/lang/zh-cn/zh-cn.js"></script>@*函数公式插件引入的js*@
<script type="text/javascript" charset="utf-8" src="~/Scripts/ueditor/kityformula-plugin/addKityFormulaDialog.js"></script>
<script type="text/javascript" charset="utf-8" src="~/Scripts/ueditor/kityformula-plugin/getKfContent.js"></script>
<script type="text/javascript" charset="utf-8" src="~/Scripts/ueditor/kityformula-plugin/defaultFilterFix.js"></script>@{ViewBag.Title = "UEditorDemo";
}<script type="text/javascript">var editor = new baidu.editor.ui.Editor({UEDITOR_HOME_URL: '/Scripts/ueditor/',//配置编辑器路径iframeCssUrl: '/Scripts/ueditor/themes/iframe.css',//样式路径initialContent: '',//初始化编辑器内容autoHeightEnabled: true,//高度自动增长minFrameHeight: 500,//最小高度autoFloatEnabled: true,initialFrameWidth: 784,initialFrameHeight: 400});editor.render('editor');
</script></div>@using (Html.BeginForm("Index", "UEditor", FormMethod.Post))
{<div></div><div>内容</div><div>  <textarea id="editor" name="editor"></textarea></div><input type="submit" value="提交" />
}<div><!--转化图片格式的--><button οnclick="ReplaceImage()">imagebase64替换为image</button><button οnclick="getAllHtml()">获得整个html的内容</button><button οnclick="getContent()">获得内容</button><button οnclick="setContent()">写入内容</button><button οnclick="setContent(true)">追加内容</button><button οnclick="getContentTxt()">获得纯文本</button><button οnclick="getPlainTxt()">获得带格式的纯文本</button><button οnclick="hasContent()">判断是否有内容</button><button οnclick="setFocus()">使编辑器获得焦点</button><button οnmοusedοwn="isFocus(event)">编辑器是否获得焦点</button><button οnmοusedοwn="setblur(event)">编辑器失去焦点</button></div>
<div><button οnclick="getText()">获得当前选中的文本</button><button οnclick="insertHtml()">插入给定的内容</button><button id="enable" οnclick="setEnabled()">可以编辑</button><button οnclick="setDisabled()">不可编辑</button><button οnclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button><button οnclick=" UE.getEditor('editor').setShow()">显示编辑器</button><button οnclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
</div><div><button οnclick="getLocalData()">获取草稿箱内容</button><button οnclick="clearLocalData()">清空草稿箱</button>
</div><div><button οnclick="createEditor()">创建编辑器</button><button οnclick="deleteEditor()">删除编辑器</button>
</div>
<script type="text/javascript">//实例化编辑器//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例var ue = UE.getEditor('editor');//将image的src从base64替换为文件名function ReplaceImage() {ue.getKfContent(function (content) { });}function isFocus(e) {alert(UE.getEditor('editor').isFocus());UE.dom.domUtils.preventDefault(e)}function setblur(e) {UE.getEditor('editor').blur();UE.dom.domUtils.preventDefault(e)}function insertHtml() {var value = prompt('插入html代码', '');UE.getEditor('editor').execCommand('insertHtml', value)}function createEditor() {enableBtn();UE.getEditor('editor');}function getAllHtml() {alert(UE.getEditor('editor').getAllHtml())}function getContent() {var arr = [];arr.push("使用editor.getContent()方法可以获得编辑器的内容");arr.push("内容为:");arr.push(UE.getEditor('editor').getContent());alert(arr.join("\n"));}function getPlainTxt() {var arr = [];arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");arr.push("内容为:");arr.push(UE.getEditor('editor').getPlainTxt());alert(arr.join('\n'))}function setContent(isAppendTo) {var arr = [];arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);alert(arr.join("\n"));}function setDisabled() {UE.getEditor('editor').setDisabled('fullscreen');disableBtn("enable");}function setEnabled() {UE.getEditor('editor').setEnabled();enableBtn();}function getText() {//当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容var range = UE.getEditor('editor').selection.getRange();range.select();var txt = UE.getEditor('editor').selection.getText();alert(txt)}function getContentTxt() {var arr = [];arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");arr.push("编辑器的纯文本内容为:");arr.push(UE.getEditor('editor').getContentTxt());alert(arr.join("\n"));}function hasContent() {var arr = [];arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");arr.push("判断结果为:");arr.push(UE.getEditor('editor').hasContents());alert(arr.join("\n"));}function setFocus() {UE.getEditor('editor').focus();}function deleteEditor() {disableBtn();UE.getEditor('editor').destroy();}function disableBtn(str) {var div = document.getElementById('btns');var btns = UE.dom.domUtils.getElementsByTagName(div, "button");for (var i = 0, btn; btn = btns[i++];) {if (btn.id == str) {UE.dom.domUtils.removeAttributes(btn, ["disabled"]);} else {btn.setAttribute("disabled", "true");}}}function enableBtn() {var div = document.getElementById('btns');var btns = UE.dom.domUtils.getElementsByTagName(div, "button");for (var i = 0, btn; btn = btns[i++];) {UE.dom.domUtils.removeAttributes(btn, ["disabled"]);}}function getLocalData() {alert(UE.getEditor('editor').execCommand("getlocaldata"));}function clearLocalData() {UE.getEditor('editor').execCommand("clearlocaldata");alert("已清空草稿箱")}
</script>

想把内容保存进去,但是有HTML标签,正则处理的代码:

 public static string CleanHtml(string strHtml){if (string.IsNullOrEmpty(strHtml))return strHtml;//删除脚本//strHtml = Regex.Replace(strHtml, "(+'\'+<script(.+?)+'\'+</script+'\'+>)|(+'\'+<style(.+?)+'\'+</style+'\'+>)", "", RegexOptions.IgnoreCase | RegexOptions.Singleline);strHtml = Regex.Replace(strHtml, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);//删除标签var r = new Regex(@"</?[^>]*>", RegexOptions.IgnoreCase);Match m;for (m = r.Match(strHtml); m.Success; m = m.NextMatch()){strHtml = strHtml.Replace(m.Groups[0].ToString(), "");}return strHtml.Trim();}

转载于:https://www.cnblogs.com/sunliyuan/p/8609454.html

.Net(C#)用正则表达式清除HTML标签(包括script和style),保留纯本文(UEdit中编写的内容上传到数据库)...相关推荐

  1. js插件---IUpload文件上传插件(包括图片)

    js插件---IUpload文件上传插件(包括图片) 一.总结 一句话总结:上传插件找到真正上传位置的代码,这样就可以知道整个上传插件的逻辑了, 找资料还是github+官方 1.如何在js中找到真正 ...

  2. 码云上传代码添加标签_第一次使用Git Bash Here 将本地代码上传到码云

    当我们安装成功git工具时候,初次使用Git时,需要Git进行配置. 1.点击桌面上的这个图标 ,打开Git Bash:如图所示 2.配置自己的用户名和邮箱 git config --global u ...

  3. 原生input标签实现ajax单文件上传和多文件上传

    自己还是一个菜鸟的时候,有次项目经理让我用Java做一个多文件上传的功能.那时候技术学得很渣,最多只能够实现单文件上传.做了一个星期都没有做出来,于是项目经理不留半点情面,当着办公室所有人的面痛批我一 ...

  4. word自动消除html标签,清理Word生成HTML的冗余;清理与清除HTML标签

    众所周知,当直接将word中的内容复制到网页上时,会产生很多冗余代码: 而现在,在线编辑器又很普遍:就包括,现在用的百度空间的这个文本编辑器,如果直接从WORD中写好的文章复制进来,本来没有几个字,结 ...

  5. Android中利用Jsoup让WebView清除Html标签并让图片适应大小并居中

    在App应用中,我们常常会加载一些新闻.通知等内容,这些内容很多来自于数据库中存储的HTML文本,里面的标签杂乱不堪,且内容中又包括图片等. 处理这些内容,我们可以利用正则表达式来处理,但标签太多,太 ...

  6. 使用正则过滤掉html标签,正则表达式过滤html标签

    正则表达式如何过滤HTML标签中的属性值 去掉html标签: str.replace(//g,"") 去掉标签里面的属性: str.replace(//g,"" ...

  7. ios html正则表达式,ios 正则表达式去html标签

    ios 正则表达式去html标签 [2021-01-27 12:53:55]  简介: php正则表达式去掉html的方法:首先使用"htmlspecialchars_decode" ...

  8. js正则表达式匹配span标签

    1.js正则表达式匹配span标签 const spans = htmlStr.match(/<span (.*?)>(.*?)<\/span>/g) 2.js正则表达式–获取 ...

  9. 清除html标签+清除html标签,字符串截取

    /*** 清除html标签* @author TechLee*/ function clear_tags($str) {$str = strip_tags($str);//首先去掉头尾空格$str = ...

最新文章

  1. 4、EIGRP配置实验之手动汇总
  2. pandas获取数据行号,删除行数据
  3. Java8 - 使用CompletableFuture 构建异步应用
  4. 带你了解Node.js包管理工具:包与NPM
  5. php计算两个日期之间的小时数,PHP_php 计算两个时间戳相隔的时间的函数(小时),这个是可以具体到小时的php代 - phpStudy...
  6. SpringBoot + Redis + Shiro 实现权限管理
  7. HTTPS那些事(三)攻击实例与防御(转载)
  8. 由装饰者模式来深入理解Java I/O整体框架
  9. Java版小米商城项目简介
  10. 程序员突然倒地!中软国际回应称系低血糖引发
  11. 一个简单的搜狗微信公众号案例
  12. 谁说bug解决不了?试试这个使用日志法
  13. C#语言 Asp.net旅游网站在线旅游信息网站(旅游系统旅游网站)旅游管理系统旅游景区旅游网站
  14. 摄氏度和华氏度的换算
  15. 雨伞被拿错,你怎么办?!
  16. 武汉软件工程职业学院普通话测试站,湖北普通话测试中心地址及联系方式一览表(65个)...
  17. 技术背景的创业者由于其秉性容易犯三种错误
  18. 纯perl语言计算文件的crc32值
  19. 4月1起入境泰国取消核酸检测,来曼谷旅游,这6座寺庙必打卡
  20. ubuntu 20.04更新阿里源 清华源

热门文章

  1. 【Qt】QModbusPdu类
  2. 【Linux系统编程应用】Linux音频编程实战(一)
  3. [Qt教程] 第35篇 网络(五)获取本机网络信息
  4. pythonasyncio在哪个版本好_什么情况下需要使用 Python 的 asyncio 模块?
  5. matlab搭建sdn,软件定义网络SDN简介和简单仿真实验
  6. 每天一道LeetCode-----计算二叉树的最大深度及最小深度,判断二叉树是否是高度平衡二叉树
  7. 搜索插入位置—leetcode35
  8. 双系统引导修复与引导项删除
  9. ARM指令中STM和LDM的理解误区
  10. CF - 741(C. Arpa’s overnight party and Mehrdad’s silent entering) 二分图构造