kindeditor在光标处插入编辑器外的数据

页面

               <div class="form-group clearfix">
                            <label class="control-label col-sm-3 col-md-3 col-lg-3 m-from-fon1" for="userName">用户</label>
                            <div class="col-sm-9 col-md-6 col-lg-6">
                                <input id="userName" name="userName" class="form-control dddd" type="button" value="用户名"/>
                                <input id="email" name="email" class="form-control dddd" type="button" value="邮箱"/>
                            </div>
                        </div>

js

$(document).ready(function () {
  
    buildEditor();
    $(".dddd").on("click",function(){
        //alert($(this).context.name); 拿到name
        var startOffset = contentEditor.cmd.range.startOffset;//kindEditor中当前光标的位置索引值startOffset
        contentEditor.insertHtml('<strong>${'+$(this).context.name+'}</strong>');//js插入指定的HTML内容到光标处。
    });
});

var contentEditor;

function buildEditor() {
    KindEditor.ready(function (K) {
        contentEditor = K.create('#content', KindEditor.buildOption('/kindeditor/upload.html', 'attachFile'));
    });


}

 

posted @ 2016-10-08 14:43  夏末、初秋  阅读(647)  评论(0编辑  收藏  举报