百度編輯器editor的使用

一.首先下載ueditor的文件javascript

連接:https://pan.baidu.com/s/16fGsenCJHyxptYEToczyVA
提取碼:zvyj
複製這段內容後打開百度網盤手機App,操做更方便哦css

 

在項目裏建立一個Libs的文件夾,把整個文件拉入裏面java

引用腳本jquery

<script src="~/Scripts/jquery-3.3.1.js"></script>
<script src="~/Content/jquery.unobtrusive-ajax.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/Libs/ueditor/ueditor.config.js"></script>
<!-- 編輯器源碼文件 -->
<script type="text/javascript" src="/Libs/ueditor/ueditor.all.js"></script>
<!-- 實例化編輯器 -->
<script src="~/Libs/ueditor/lang/zh-cn/zh-cn.js"></script>ajax

代碼:數據庫

    @Html.BeginForm("進入帖子", "WuDi")
        {
        <textarea id="editor" name="editor"></textarea> //實例化百度編輯器
        <input type="submit" id="btnBaidu" value="提交" />
        }json


<script>
    var ue = UE.getEditor("editor", {
        toolbars: [
            ['redo', 'snapscreen', 'bold', 'horizontal', 'cleardoc',
                'fontfamily', 'forecolor', 'fontsize', 'simpleupload', 'insertimage'
                , 'emotion', 'map', 'insertvideo', 'attachment']
        ], 
        iframeCssUrl: '/ueditor/utf8-jsp/themes/iframe.css',// 引入css
        autoHeightEnabled: false,
        autoFloatEnabled: true,
        initialFrameWidth: 700,
        initialFrameHeight: 150
    });
  
</script>jsp

 

效果圖:編輯器

 

找到config.json,修改路徑,圖片就會顯示在百度編輯器的編輯框裏ide

效果圖:

而後點擊提交,就能夠把文本框的輸入的文本以及圖片傳到後臺

後臺代碼:

        [HttpPost]
        [ValidateInput(false)]  //這個必寫,不寫會報錯
        public ActionResult Index(FormCollection fc)
        {
            string content = fc["editor"];

             //下面就是把content保存到數據庫操做,不詳細些;
            return View();
        }

 

效果圖:

顯示在頁面上,就先把數據從數據庫拿過來,而後把值輸出就能夠顯示對應的文本以及圖片

@Html.Raw(@item.PingLun_nei)  括號裏面是存放保存圖片及文本的字段名字;

相關文章
相關標籤/搜索