通过jQuery创建文本编辑器 [英] Creating a text editor through jquery

查看:124
本文介绍了通过jQuery创建文本编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧...解释很简单,我想创建一个文本编辑器,就像在其中键入内容并在其下方设置并显示文本的stackoverflow一样.

Well... Explanation is simple I want to create a text editor just like stackoverflow where you type and beneath the text is formatted and shown.

让事情变得简单

这是我尝试过的简单方法.

This is a simple thing I tried.

`https://jsfiddle.net/dh4qpzzv/`

但是它不会将文本推到跨度.

But it doesn't push the text to the span.

推荐答案

正如Amani所说,您应该使用一些外部库,例如CKEditor或TineMCE.然后,在更改时绑定 事件以替换目标元素的内容.

As Amani said, you should use some external library, e.g. CKEditor or TineMCE. Then, bind on change event to replace the content of destination element.

JSFiddle

HTML:

<textarea name="editor"></textarea>

<div id="result">
    <p>Put some text in the editor to see the preview.</p>
</div>

JS:

var editor = CKEDITOR.replace('editor', {
    height: 100
});

editor.on('change', function () {
   $('#result').html(this.getData())
});

这篇关于通过jQuery创建文本编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆