在NicEdit WYSIWYG中插入HTML [英] Insert HTML in NicEdit WYSIWYG

查看:136
本文介绍了在NicEdit WYSIWYG中插入HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在NicEdit创建的div中的游标位置插入文本/代码?

How can I insert text/code at the cursors place in a div created by NicEdit?

我试过阅读文档并创建自己的插件,但是我想让它在没有工具栏的情况下工作(模态窗口)

I've tried to read the documentation and create my own plugin, but I want it to work without the tool bar (Modal Window)

推荐答案

这是一个快速的解决方案,只在firefox中测试过。但它适用于IE和其他浏览器。

This is a quick solution and tested in firefox only. But it works and should be adaptable for IE and other browsers.

function insertAtCursor(editor, value){
    var editor = nicEditors.findEditor(editor);
    var range = editor.getRng();                    
    var editorField = editor.selElm();
    editorField.nodeValue = editorField.nodeValue.substring(0, range.startOffset) +
                            value +
                            editorField.nodeValue.substring(range.endOffset, editorField.nodeValue.length);
}

这篇关于在NicEdit WYSIWYG中插入HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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