search
HomeWeb Front-endHTML TutorialAn easy-to-use HTML editor (UEditor) tutorial

Regarding HTML editors, I have tried FCKeditor, the upgraded version of CKeditor, and TinyMCE. Recently, I am trying to use Baidu’s UEditor. In comparison, I still feel that the configuration of UEditor is relatively simple, it is quick to get started and the documentation and examples are complete. So here we take UEditor1.2.3.0PHP version UTF-8 version as an example to sort out the usage process of UEditor.

1. First is the document structure of UEditor

HTML编辑器UEditor的简单使用

## _examples: Example pages of various versions of the editor

_src: JS file

##dialogs: Pop-up dialog box corresponding Resources and JS files

lang: Language pack file

PHP: File upload processing, remote image capture, online image management, screen Screenshot related files

themes: style images and style files

third-party: third-party plug-ins

editor_all.js: a packaged file of all files in the _src directory

editor_all_min.js: a compressed version of the editor_all.js file, which can be used only during formal deployment

editor_config.js: Editor configuration file

2. System configuration

UEditor's configuration can be divided into two types: system default configuration and user-defined configuration.

The system default configuration is scattered in each corresponding core or plug-in file and is invisible to users. Works when user comments out custom configuration. User-defined configurations include two types, one is located in the editor_config.js file, with a higher priority than the system default configuration; the other is located in the parameters passed in when instantiating the editor, with a higher priority Highest. By default, UEditor comments out all configuration items that can be omitted in editor_congfig.js, and adopts the system default configuration. If the comment is uncommented, the configuration item shall prevail; uncommented configuration items require users to follow the actual project conditions. fill in.

The following is a simple configuration defined by myself:

<script type="text/javascript">
// 自定义的编辑器配置项,此处定义的配置项将覆盖editor_config.js中的同名配置
var editorOption = {
//这里可以选择自己需要的工具按钮名称,此处仅选择如下四个
toolbars:[[&#39;FullScreen&#39;, &#39;Source&#39;, &#39;Undo&#39;, &#39;Redo&#39;]]
//更多其他参数,请参考editor_config.js中的配置项
};

The most important configuration is line 28 about The configuration of URL parameters, related to image upload, processing and other paths, needs to be configured as the relative path or absolute path of uediotr on the website. For example, if my project name is t and the root directory is www, the URL value is set as follows:

URL = window.UEDITOR_HOME_URL||"/t/UEditor/";

3.引入配置文件,JS文件和主题CSS文件

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="UEditor/editor_config.js"></script>
<script type="text/javascript" src="UEditor/editor_all.js"></script>
<link rel="stylesheet" href="UEditor/themes/default/ueditor.css">

      4.创建编辑器实例及其DOM容器    

<form action="" method="post" name="myForm">
<!--以下引入UEditor编辑器界面-->
<script type="text/plain" id="editor" name="myContent"></script> //此处不设置name,则editor默认名字为"editorValue",可以在
 //editor_config.js中配置参数textarea,或者在此处设置
<input type="submit" name="submit" value="upload"/>
</form>

       5.设置选项并且渲染编辑器

       如果需要有不同设置的ueditor,可以分别定义之后设置不同的自定义选项再渲染编辑器,

<script type="text/plain" id="myEditor" style="width:800px">
</script>
<script type="text/plain" id="myEditor1" style="width:800px">
<p>这里我可以写一些输入提示</p>
</script>
<script type="text/javascript">
var editor_a = new baidu.editor.ui.Editor();
editor_a.render( &#39;myEditor&#39; ); //此处的参数值为编辑器的id值

var editor_a1 = new baidu.editor.ui.Editor({
//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
toolbars:[[&#39;FullScreen&#39;, &#39;Source&#39;, &#39;Undo&#39;, &#39;Redo&#39;,&#39;Bold&#39;]],
//focus时自动清空初始化时的内容
//更多其他参数,请参考editor_config.js中的配置项
});
editor_a1.render( &#39;myEditor1&#39; );
</script>

       6.前后台数据交互

      对于PHP可以直接用$_POST['ueditorName']获取编辑器的值,其中ueditorName的值为初始化编辑器时ueditor的name值。

       以下为完整的渲染2个ueditor的代码

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>UEditor</title>
<!--以下为引入UEditor资源部分-->
<script type="text/javascript" src="UEditor/editor_config.js"></script>
<script type="text/javascript" src="UEditor/editor_all.js"></script>
<link rel="stylesheet" href="UEditor/themes/default/ueditor.css">
<!--以上为引入UEditor资源部分-->
</head>
<body>
<form action="test.php" method="post" name="myForm">
<!--以下引入UEditor编辑器界面-->
<script type="text/plain" id="myEditor" name="myContent">这是一个测试还是一个测试</script>
<input type="submit" name="submit" value="upload"/>
</form>
<script type="text/plain" id="myEditor1"><p>这里我可以写一些输入提示</p></script>
<script type="text/javascript">
    var editor_a = new baidu.editor.ui.Editor();
    editor_a.render( &#39;myEditor&#39; ); //此处的参数值为编辑器的id值
    
    var editor_a1 = new baidu.editor.ui.Editor({
    //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
    toolbars:[[&#39;FullScreen&#39;, &#39;Source&#39;, &#39;Undo&#39;, &#39;Redo&#39;,&#39;Bold&#39;]],
    //focus时自动清空初始化时的内容
    autoClearinitialContent:true,
    //更多其他参数,请参考editor_config.js中的配置项
});
    editor_a1.render( &#39;myEditor1&#39; );
</script>
</body>
</html

【相关推荐】

1. 免费html在线视频教程

2. html开发手册

3. php.cn原创html5视频教程

The above is the detailed content of An easy-to-use HTML editor (UEditor) tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

What is the viewport meta tag? Why is it important for responsive design?What is the viewport meta tag? Why is it important for responsive design?Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it?What is the purpose of the <iframe> tag? What are the security considerations when using it?Mar 20, 2025 pm 06:05 PM

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft